2013-01-22 36 views
0

含有環帖碼的代碼下面應顯示的頁面隨後某些頁面內容的內容。簡化而在WordPress

<!-- Section --> 
    <section> 
    <?php if (have_posts()): while (have_posts()) : the_post(); ?> 

     <!-- Article --> 
     <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> 

      <!-- Posts for homepage --> 
      <?php 
       if (is_front_page()) { ?> 
        <?php the_content(); ?> 

        <!-- Show page content according to page ID --> 
        <div class="title-home clearfix"> 
         <div class="four title-home-text">Services Spotlight</div> 
         <div class="four title-home-text" style="margin-left: 115px;">Industry Expertise</div> 
         <div class="four title-home-text" style="margin-left: 125px;">Features &amp; Benefits</div> 
        </div> 
        <div class="four-wrapper clearfix"> 
        <div class="four-container"> 
         <div class="four-col line"> 
         <?php 
          query_posts('page_id=40'); 
          while (have_posts()): the_post(); 
           the_content(); 
          endwhile; 
         ?> 
         </div> 
         <a href="" class="read-morebtn"> read more </a> 
        </div> 

        <div class="four-container">  
         <div class="four-col line"> 
         <?php 
          query_posts('page_id=41'); 
          while (have_posts()): the_post(); 
           the_content(); 
          endwhile; 
         ?> 
         </div> 
         <a href="" class="read-morebtn"> read more </a> 
        </div> 

        <div class="four-container">  
        <div class="four-col line"> 
        <?php 
         query_posts('page_id=42'); 
         while (have_posts()): the_post(); 
          the_content(); 
         endwhile; 
        ?> 
        </div> 
        <a href="" class="read-morebtn"> read more </a> 
        </div> 


        <div class="four-container">  
         <div class="four-col line"> 
          <?php if(!function_exists('dynamic_sidebar') || !dynamic_sidebar('widget-area-3')) ?> 
         </div> 
        </div> 

        </div> 


       <?php 
       } 
       else { 
       ?> 
        <h1><?php the_title(); ?> </h1> 
        <?php the_content(); ?> 
       <?php } ?> 
      <!-- end post homepage --> 




      <br class="clear"> 

      <?php edit_post_link(); ?> 

     </article> 
     <!-- /Article --> 

     <?php endwhile; ?> 

     <?php else: ?> 

     <!-- Article --> 
     <article> 
      <h2><?php _e('Sorry, nothing to display.', 'html5blank'); ?></h2> 
     </article> 
     <!-- /Article --> 

    <?php endif; ?> 

    </section> 

    <!-- /Section --> 

<?php get_footer(); ?> 

然而,它顯示最近查詢的循環。

輸出代碼:

<article id="post-6" class="post-6 page type-page status-publish hentry"> 
<article id="post-42" class="post-42 page type-page status-publish hentry"> 

post-42不應該顯示的文章。

而且,我知道代碼是不是簡化了使用while循環。我想修復article問題並簡化此代碼。

回答

0

食品法典委員會建議不要使用副圈query_posts按Codex Query Posts Page

看起來你是在主迴路(文章),因爲query_posts改變主循環跺腳。如果你想使用query_posts,建議在完成時調用wp_reset_query()。首選的方法是使用WP_query()。

+0

它的工作原理!我在'while'後面加了'wp_reset_query();'。謝謝! – woninana