2013-11-04 2 views
-1

블로그 게시물 [latest_posts.php]과 하나의 블로그 게시물 [blog.php]을 표시하는 페이지가있는 페이지가 있습니다. latest_posts.php에 이미지 제목을 연결하여 클릭 한 특정 게시물을 표시 할 blog.php로 리디렉션합니다.동적 페이지로 리디렉션

latest_posts.php ---->

<div class="main blog"> 

     <!-- Header --> 
     <h2 class="underline"> 
      <span>What&#039;s new</span> 
      <span></span> 
     </h2> 
     <!-- /Header --> 

     <!-- Posts list --> 
     <ul class="post-list post-list-1"> 


       <?php 

       /* Fetches Date/Time, Post Content and title */ 

       include 'dbconnect.php'; 

       $sql = "SELECT * FROM wp_posts"; 
       $res = mysql_query($sql); 


       while ($row = mysql_fetch_array($res)) { 
       ?> 


      <!-- Post #1 --> 
      <li class="clear-fix"> 

       <!-- Date --> 
       <div class="post-list-date"> 
        <div class="post-date-box"> 


         <?php 
          //Timestamp broken down to show accordingly 
          $timestamp = $row['post_date']; 
          $datetime = new DateTime($timestamp); 
          $date = $datetime->format("d"); 
          $month = $datetime->format("M"); 
        ?> 
          <h3> <?php echo $date; ?> </h3> 
          <span> <?php echo $month; ?> </span> 

        </div> 
       </div> 
       <!-- /Date --> 

       <!-- Image + comments count --> 
       <div class="post-list-image"> 
        <!-- Image --> 
        <div class="image image-overlay-url image-fancybox-url"> 
         <a href="post.php" class="preloader-image"> 
          <?php 
               echo '<img src="', $row['image'], '" alt="' , $row['post_title'] , '\'s Blog Image" />'; 
          ?> 
         </a> 
        </div> 
        <!-- /Image --> 
       </div> 
       <!-- /Image + comments count --> 

       <!-- Content --> 
       <div class="post-list-content"> 
        <div> 
         <!-- Header --> 
         <h4> <a href="post.php? . $row['ID'] . "> <?php echo $row['post_title']; ?> </a> </h4> 



         <!-- /Header --> 

         <!-- Excerpt --> 
         <p> 
          <?php echo $row ['post_content']; }?> 
         </p> 
         <!-- /Excerpt --> 

        </div> 

       </div> 
       <!-- /Content --> 

      </li> 
      <!-- /Post #1 --> 

     </ul> 
     <!-- /Posts list --> 


     <a href="blog.php" class="button-browse">Browse All Posts</a> 

    </div> 

    <?php require_once('include/twitter_user_timeline.php'); ?> 

blog.php ---> 미리

<?php require_once('include/header.php'); ?> 

    <body class="blog"> 

     <?php require_once('include/navigation_bar_blog.php'); ?> 

     <div class="blog"> 

      <div class="main"> 

       <!-- Header --> 
       <h2 class="underline"> 
        <span>What&#039;s new</span> 
        <span></span> 
       </h2> 
       <!-- /Header --> 

       <!-- Layout 66x33 --> 
       <div class="layout-p-66x33 clear-fix"> 

        <!-- Left column --> 
        <!-- <div class="column-left"> --> 

         <!-- Posts list --> 
         <ul class="post-list post-list-2"> 

         <?php 

         /* Fetches Date/Time, Post Content and title with Pagination */ 

         include 'dbconnect.php'; 

         //sets to default page 
         if(empty($_GET['pn'])){ 
          $page=1; 
         } else { 
          $page = $_GET['pn']; 

         } 
         // Index of the page 
         $index = ($page-1)*3; 

         $sql = "SELECT * FROM `wp_posts` ORDER BY `post_date` DESC LIMIT " . $index . " ,3"; 
         $res = mysql_query($sql); 

         //Loops through the values 
         while ($row = mysql_fetch_array($res)) { 
         ?> 




          <!-- Post #1 --> 
          <li class="clear-fix"> 
           <!-- Date --> 
           <div class="post-list-date"> 
            <div class="post-date-box"> 

            <?php 
              //Timestamp broken down to show accordingly 
              $timestamp = $row['post_date']; 
              $datetime = new DateTime($timestamp); 
              $date = $datetime->format("d"); 
              $month = $datetime->format("M"); 
            ?> 
              <h3> <?php echo $date; ?> </h3> 
              <span> <?php echo $month; ?> </span> 

            </div> 
           </div> 
           <!-- /Date --> 

           <!-- Image + comments count --> 
           <div class="post-list-image"> 

            <!-- Image --> 
            <div class="image image-overlay-url image-fancybox-url"> 
             <a href="post.php" class="preloader-image"> 
             <?php echo '<img src="', $row['image'], '" alt="' , $row['post_title'] , '\'s Blog Image" />'; ?> 
             </a> 
            </div> 
            <!-- /Image --> 
           </div> 
           <!-- /Image + comments count --> 
           <!-- Content --> 
           <div class="post-list-content"> 
            <div> 

             <!-- Header --> 
             <h4> <a href="post.php"> <?php echo $row['post_title']; ?> </a> </h4> 
             <!-- /Header --> 
             <!-- Excerpt --> 
             <p> <?php echo $row ['post_content']; ?> </p> 
             <!-- /Excerpt --> 
            </div> 
           </div> 
           <!-- /Content --> 
          </li> 
          <!-- /Post #1 --> 



         <?php } // close while loop ?> 

         </ul> 
         <!-- /Posts list --> 



         <div><!-- Pagination --> 

          <ul class="blog-pagination clear-fix"> 

           <?php 

           //Count the number of rows 
           $numberofrows = mysql_query("SELECT COUNT(ID) FROM `wp_posts`"); 
           //Do ciel() to round the result according to number of posts 
           $postsperpage = 4; 
           $numOfPages = ceil($numberofrows/$postsperpage); 


           for($i=1; $i < $numOfPages; $i++) { 

            //echos links for each page 
            $paginationDisplay = '<li><a href="blog.php?pn=' . $i . '">' . $i . '</a></li>'; 
            echo $paginationDisplay; 


           } 



           ?> 
           <!-- 
           <li><a href="#" class="selected">1</a></li> 
           <li><a href="#">2</a></li> 
           <li><a href="#">3</a></li> 
           <li><a href="#">4</a></li> 
           -->      

          </ul> 
         </div><!-- /Pagination --> 

        <!-- /div> --> 
        <!-- Left column --> 


       </div> 
       <!-- /Layout 66x33 --> 

      </div> 

     </div> 

     <?php require_once('include/twitter_user_timeline.php'); ?> 
     <?php require_once('include/footer_blog.php'); ?> 

감사합니다.

+1

그렇게 한 일 멀리? –

+1

코드를 보여줄 수 있습니까? –

+0

이 질문에 태그가 있다는 것을보고 싶습니까 –

답변

0

자습서를 검색해야합니다. :) 주위에 멋진 것들이 있습니다.

귀하의 블로그는 데이터베이스에 존재합니다. 이러한 데이터베이스 레코드에는 각각 고유 ID가 있어야합니다.

latest_blogs 페이지에? id = (예제)를 추가하면 링크를 클릭 할 때 idover를 전달할 수 있습니다.

이제 블로그 페이지에서 PHP 변수 $ _GET [ 'id']에 블로그 ID가 포함됩니다.

희망이 조금 있습니다. 문제에 대한 코드를 보지 않고

1

나는 논리는이 같은 것으로 추정에 ..

당신이 같은 (당신이 ID를 포함 $ 포스트 같은 변수가 가정을 할 것 latest_posts.php 및 제목, 또는 그와 같은 스키마) :

당신이 URL에서 ID를 잡아 어떻게 든 그것을 볼 필요가 것 blog.php에서 다음
<a href="blog.php?id=<?php echo $post["id"]; ?>"><?php echo $post["title"]; ?></a> 

..

<?php 
$id = $_GET["id"]; 

$post = lookup_post_somehow($id); 

if($post) { 
    // render post 
} else { 
    // 404, blog post not found.. 
} 
?> 
+0

이 남자는 받아 들여진 대답이 가치가있다. 내 것보다 훨씬 낫다 –

+0

고마워! 귀하의 답변은 같은 목적을 가지고 있습니다 :) 나는 내 글을 쓰기 전에 당신을 본적이 없다면 나는 게시하지 않았을 것입니다. – Mingle

+0

더 자세한 솔루션을 제공해 주시면 감사하겠습니다. – binarydev