2012-08-28 78 views
0

我是一種WordPress的noob,但試圖實現我的HTML/CSS主題到WP,但我偶然發現了一個奇怪的bug ...每當我添加另一個帖子,home.php頁面重複自己後結束頁面:○ 這裏是我的home.php的HTML/PHP代碼,這將是我的主要頁面:WordPress的home.php重複內容?

<?php 
    get_header(); 
?>  
     <!-- WRAPPER START --> 
     <section id="wrapper"> 
      <?php 
       if(have_posts()): 
        while(have_posts()): 
         the_post(); 
      ?> 
      <!-- start dynamic part --> 
      <!-- NEWS START --> 

      <div id="slider">  
       <article> 
        <h2> 
         <a href="<?php the_permalink();?>"><?php the_title(); ?></a> 
        </h2> 

        <p class="m-post-info"> 
         Posted by <a href="<?php the_permalink();?>"><?php the_author(); ?></a> on 
         <?php the_date('d-m-Y'); ?> | 
         <a href="<?php the_permalink();?>"><?php comments_number('no comment', 'one comment', '% comments'); ?></a> 
        </p> 

        <div> 
         <?php the_content(); ?> 
        </div> 

        <a id="arrow-left" href="#" title="Previous"></a> 
        <a id="arrow-right" href="#" title="Next"></a> 
       </article> 
      </div> 

      <!-- NEWS END --> 


      <!-- MAIN CONTENT START--> 

      <section id="main-content"> 


       <!-- 3COLUMN LAYOUT START --> 

       <div id="column-1"> 
        <h3> 
         POPULAR ARTICLES 
        </h3> 
        <article class="news-article"> 
         <header> 
          <h4> 
           <a href="<?php the_permalink();?>"><?php the_title(); ?></a> 
          </h4> 
          <p class="post-info"> 
           Posted by <a href="<?php the_permalink();?>"><?php the_author(); ?></a> in on <?php the_date('d-m-Y'); ?> | <a href="<?php the_permalink();?>"><?php comments_number('no comment', 'one comment', '% comments'); ?></a> 
          </p> 
         </header> 
         <img src="<?php echo get_template_directory_uri() ?>/images/image-small.png" title="Riots" alt="Example Image 1" width="75" height="75" /> 
         <div class="post-text"> 
          <?php the_excerpt(); ?> 
         </div> 
        </article> 
        <article class="news-article"> 
         <header> 
          <h4> 
           <a href="<?php the_permalink();?>"><?php the_title(); ?></a> 
          </h4> 
          <p class="post-info"> 
           Posted by <a href="<?php the_permalink();?>"><?php the_author(); ?></a> in on <?php the_date('d-m-Y'); ?> | <a href="<?php the_permalink();?>"><?php comments_number('no comment', 'one comment', '% comments'); ?></a> 
          </p> 
         </header> 
         <img src="<?php echo get_template_directory_uri() ?>/images/image-small.png" title="Riots" alt="Example Image 1" width="75" height="75" /> 
         <div class="post-text"> 
          <?php the_excerpt(); ?> 
         </div> 
        </article> 
       </div> 

       <div id="column-2"> 
        <h3> 
         RECENT COMMENTS 
        </h3> 

        <div class="comment"> 
         <?php 
         $comments = get_comments('status=approve&number=3'); 
          foreach($comments as $comment) :?> 
          <?php $my_id = $comment->comment_post_ID ; $post_id_comms = get_post($my_id); $title = $post_id_comms->post_title;?> 
         <p class="user"> 
          <?php echo($comment->comment_author);?> <span class="text-decoration">says</span><br /> 
          </p> 
         <p class="user-text"> 
          <?php echo($comment->comment_content);?><br /> 
         </p> 
         <?php endforeach;?> 
        </div> 
       </div> 

       <div id="column-3"> 
        <h3> 
         LIFESTREAM 
        </h3> 
        <article class="news-article"> 
         <header> 
          <h4> 
           <a href="<?php the_permalink();?>"><?php the_title(); ?></a> 
          </h4> 
          <p class="post-info"> 
           Posted by <a href="<?php the_permalink();?>"><?php the_author(); ?></a> in on <?php the_date('d-m-Y'); ?> | <a href="<?php the_permalink();?>"><?php comments_number('no comment', 'one comment', '% comments'); ?></a> 
          </p> 
         </header> 
         <img src="<?php echo get_template_directory_uri() ?>/images/image-small.png" title="Riots" alt="Example Image 1" width="75" height="75" /> 
         <div class="post-text"> 
          <?php the_excerpt(); ?> 
         </div> 
        </article> 
        <article class="news-article"> 
         <header> 
          <h4> 
           <a href="<?php the_permalink();?>"><?php the_title(); ?></a> 
          </h4> 
          <p class="post-info"> 
           Posted by <a href="<?php the_permalink();?>"><?php the_author(); ?></a> in on <?php the_date('d-m-Y'); ?> | <a href="<?php the_permalink();?>"><?php comments_number('no comment', 'one comment', '% comments'); ?></a> 
          </p> 
         </header> 
         <img src="<?php echo get_template_directory_uri() ?>/images/image-small.png" title="Riots" alt="Example Image 1" width="75" height="75" /> 
         <div class="post-text"> 
          <?php the_excerpt(); ?> 
         </div> 
        </article> 
       </div> 

       <!-- 3COLUMN LAYOUT END --> 

       <!-- SIDEBAR START --> 

       <aside id="tab-lists"> 
        <?php if(!dynamic_sidebar('telerik-sidebar')): ?> 
        <div> 
         <h5 id="tab1"> 
          <span>recent posts</span> 
         </h5> 
         <ul> 
          <li> 
           <a href="#">Pellentesque tincidunt, diam eget accumsan</a> 
          </li> 
          <li> 
           <a href="#">Pellentesque tincidunt, diam eget accumsan</a> 
          </li> 
          <li> 
           <a href="#">Pellentesque tincidunt, diam eget accumsan</a> 
          </li> 
          <li> 
           <a href="#">Pellentesque tincidunt, diam eget accumsan</a> 
          </li> 
          <li> 
           <a href="#">Pellentesque tincidunt, diam eget accumsan</a> 
          </li> 
          <li> 
           <a href="#">Pellentesque tincidunt, diam eget accumsan</a> 
          </li> 
         </ul> 
        </div> 
        <?php endif; ?> 
        <?php if(!dynamic_sidebar('telerik-sidebar2')): ?> 
        <div> 
         <h5 id="tab2"> 
          <span>recent posts</span> 
         </h5> 

         <ul> 
          <li> 
           <a href="#">Pellentesque tincidunt, diam eget accumsan</a> 
          </li> 
          <li> 
           <a href="#">Pellentesque tincidunt, diam eget accumsan</a> 
          </li> 
          <li> 
           <a href="#">Pellentesque tincidunt, diam eget accumsan</a> 
          </li> 
          <li> 
           <a href="#">Pellentesque tincidunt, diam eget accumsan</a> 
          </li> 
          <li> 
           <a href="#">Pellentesque tincidunt, diam eget accumsan</a> 
          </li> 
          <li> 
           <a href="#">Pellentesque tincidunt, diam eget accumsan</a> 
          </li> 
         </ul> 
        </div> 
        <?php endif; ?> 
       </aside>  

       <!-- SIDEBAR END --> 

       <!-- BIG POST START --> 
       <div id="big-post"> 
        <h3> 
         RECENT POSTS 
        </h3> 
        <article> 
         <header> 
          <h2> 
           <a href="<?php the_permalink();?>"><?php the_title(); ?></a> 
          </h2> 
          <p class="post-info"> 
           Posted by <a href="<?php the_permalink();?>"><?php the_author(); ?></a> in on <?php the_date('d-m-Y'); ?> | <a href="<?php the_permalink();?>"><?php comments_number('no comment', 'one comment', '% comments'); ?></a> 
          </p> 
         </header> 
         <img src="<?php echo get_template_directory_uri() ?>/images/image-big.png" alt="Picture" title="Example Image 2" width="214" height="214" /> 
         <div class="post-text"> 
          <?php the_content(); ?> 
         </div> 
        </article> 
       </div> 
       <!-- BIG POST END --> 

      </section> 

      <!-- MAIN CONTENT END --> 
     <!-- END DYNAMIC PART --> 
      <?php 
       endwhile; 
       endif; 
      ?> 
     </section> 

     <!-- WRAPPER END --> 

<?php 
    get_footer(); 
?> 
+0

你沒有正確地結束你的循環,你需要有1循環的每一個內容。在您的第一個<?php the_content();?>之後放置<?php endwhile;?>以查看此內容。 – SMacFadyen

回答

2

你已經得到(幾乎)你的整個頁面在loop,所以每個帖子它會重複一切。
想要結束您的帖子後關閉while,而不是在頁面末尾。

你需要後停止它:<!-- NEWS END -->

+0

+1。我也認爲'div#slider'應該在循環之外。與#箭頭左/右鏈接一起。 – powerbuoy

+0

所以我意識到我的滑塊不應該在home.php中,它現在在header.php中 - 但是當我刪除時,它不顯示......我應該在哪裏放置'<?php endwhile; 'line – user1565092

+0

它取決於你想要顯示的內容。在HTML之後發佈。 – janw

0

下我的立場不你的意思重複它的自我是什麼。

<article class="news-article"> 
    <header> 
     <h4> 
      <a href="<?php the_permalink();?>"><?php the_title(); ?></a> 
     </h4> 
     <p class="post-info"> 
      Posted by <a href="<?php the_permalink();?>"><?php the_author(); ?></a> in on <?php the_date('d-m-Y'); ?> | <a href="<?php the_permalink();?>"><?php comments_number('no comment', 'one comment', '% comments'); ?></a> 
     </p> 
    </header> 
    <img src="<?php echo get_template_directory_uri() ?>/images/image-small.png" title="Riots" alt="Example Image 1" width="75" height="75" /> 
    <div class="post-text"> 
     <?php the_excerpt(); ?> 
    </div> 
</article> 
<article class="news-article"> 
    <header> 
     <h4> 
      <a href="<?php the_permalink();?>"><?php the_title(); ?></a> 
     </h4> 
     <p class="post-info"> 
      Posted by <a href="<?php the_permalink();?>"><?php the_author(); ?></a> in on <?php the_date('d-m-Y'); ?> | <a href="<?php the_permalink();?>"><?php comments_number('no comment', 'one comment', '% comments'); ?></a> 
     </p> 
    </header> 
    <img src="<?php echo get_template_directory_uri() ?>/images/image-small.png" title="Riots" alt="Example Image 1" width="75" height="75" /> 
    <div class="post-text"> 
     <?php the_excerpt(); ?> 
    </div> 
</article> 

在我看來,你應該有這樣的代碼段只有一次:

<article class="news-article"> 
    <header> 
     <h4> 
      <a href="<?php the_permalink();?>"><?php the_title(); ?></a> 
     </h4> 
     <p class="post-info"> 
      Posted by <a href="<?php the_permalink();?>"><?php the_author(); ?></a> in on <?php the_date('d-m-Y'); ?> | <a href="<?php the_permalink();?>"><?php comments_number('no comment', 'one comment', '% comments'); ?></a> 
     </p> 
    </header> 
    <img src="<?php echo get_template_directory_uri() ?>/images/image-small.png" title="Riots" alt="Example Image 1" width="75" height="75" /> 
    <div class="post-text"> 
     <?php the_excerpt(); ?> 
    </div> 
</article> 

我做我的模板的方式,但我還是不站下的問題都沒有。

仔細看,你必須嘗試做多個循環。每個部分應該不止一次,或者你喜歡看到你的帖子,你需要一個循環。

+0

感謝您的答覆 - 通過重複本身,我的意思是整個粘貼代碼是在footer.php(全部結束後)後6次顯示的。 關於粘貼的arcticles,我會改變它們,但還沒有想出如何獲得我最近在home.php上的帖子呢,那只是暫時的......我希望。 TY,再次。 – user1565092