每页的帖子数不正确

时间:2016-04-01 作者:Peekay

我有一张单人床。php有3个循环,一个循环一个页面(相关帖子、最新帖子和实际内容)。

所有循环都使用wp\\u reset\\u postdata();在最后。

出于某种原因,我的相关帖子和最新帖子的post\\u per\\u page参数正在重新调整额外的帖子。

我不确定出了什么问题。有什么想法吗?

谢谢你的帮助。

<?php get_header(); ?>

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

  <div id="hero" style="background-image: url(\'<?php bloginfo( \'template_directory\' ) ;?>/images/slider_blog.png\')">
    <div class="row">
      <div class="small-12 columns text-center">   
        <div class="slider_text_box white">
          <h1><?php the_title(); ?></h1> 
        </div>     
      </div>
    </div>
  </div>

<!------------------------------------------------ 
--------------------------------------------------
Content Section
--------------------------------------------------
-------------------------------------------------->
  <?php $time = get_post_meta( get_the_ID(), \'single_time\', true ); ?>

  <div class="row small_section">
    <div class="small-12 medium-8 columns content">
      <div class="meta_blog text-center">
        <?php the_date(); ?> | Read Time: <?php echo $time; ?> min  | <?php the_category( \' \' ); ?> 
      </div>
      <div>
        <?php the_content(); ?>
        <div class="meta_blog text-center">
          <?php echo get_the_tag_list( \'Tags: \', \', \'); ?>
        </div>
      </div>
  <?php endwhile; 
  wp_reset_postdata();
  else : ?>
  <p><?php _e( \'Sorry, no posts matched your criteria.\' ); ?></p>
  <?php endif; ?>
    </div>
      <aside class="show-for-medium medium-4 large-3 large-offset-1 columns">
       <div class="row text-center" id="sidebar">
       <!-- Search -->
         <div class="small-12 columns">      
           <form>
             <input type="text" placeholder="Search"></input>
           </form>      
         </div>
         <!-- Newsletter signup -->
         <div class="small-12 columns">
           <div class="sidebar_containers">
             <h5>Newsletter</h5>
             <p class="small_bottom_room">Stay in Touch</p>
             <form>
               <input type="text"></input>
               <button class="small_button_orange">Sign Up</button>
             </form>
           </div>      
         </div>
         <!-- Recents Posts -->
         <div class="small-12 columns">
           <div class="sidebar_containers">
             <h5 class="small_bottom_room">Latest Posts</h5>

             <?php $args2 = array(
               \'posts_per_page\' => 1,
             ) ?>

             <?php $latest_posts = new WP_Query( $args2 ); ?>

             <?php if ( $latest_posts->have_posts() ) : while ( $latest_posts->have_posts() ) : $latest_posts->the_post(); ?>
               <div class="latest_posts">
                 <a href="<?php the_permalink(); ?>">
                   <?php the_title(); ?>
                 </a>
               </div>          

             <?php endwhile; 
             wp_reset_postdata();
             else : ?>
             <p><?php _e( \'Sorry, no posts matched your criteria.\' ); ?></p>
             <?php endif; ?>
           </div>      
         </div>

         <!-- Follow Us -->    
         <div class="small-12 columns">
           <div class="sidebar_containers">
             <h5 class="small_bottom_room">Follow Us</h5>
             <a href="#"><img src="<?php bloginfo( \'template_directory\' );?>/images/icon_facebook_orange.png" alt="" width="45" height="45"></a>
             <a href="#"><img src="<?php bloginfo( \'template_directory\' );?>/images/icon_instagram_orange.png" alt="" width="45" height="45"></a>
             <a href="#"><img src="<?php bloginfo( \'template_directory\' );?>/images/icon_linkedin_orange.png" alt="" width="45" height="45"></a>
           </div>      
         </div>
       </div>
     </aside>
  </div>



<!------------------------------------------------ 
--------------------------------------------------
Related Posts Section
--------------------------------------------------
-------------------------------------------------->

<section class="blue_bg">
 <div class="row" data-equalizer>
  <h2 class="text-center smallest_section">You Might Also Like This</h2>

<?php $args3 = array(
  \'posts_per_page\' => 5,
  \'post_type\' => \'post\'
 ); ?>

<?php $related_posts = new WP_Query( $args3 ); ?>

<?php if ( $related_posts->have_posts() ) : while ( $related_posts->have_posts() ) : $related_posts->the_post(); ?>

  <?php get_template_part( \'template_parts/related-posts\' ); ?>

<?php endwhile; 
wp_reset_postdata();
else : ?>
<p><?php _e( \'Sorry, no posts matched your criteria.\' ); ?></p>
<?php endif; ?>

  </div>
</section>

<?php get_footer(); ?>

1 个回复
最合适的回答,由SO网友:Peekay 整理而成

找到问题。这与我的一篇帖子很粘有关。找到了答案here.

相关推荐

当in_the_loop()为假时,何时以及为什么is_Single(‘my_cpt’)为真?

我正在使用模板系统的示例代码。此地址的页码:http://project.test/my_cpt/hello-post/.无法理解原因is_singular( \'my_cpt\' ) 是true 虽然in_the_loop() 是false.在页面模板中The Loop "E;“工程”:if ( have_posts() ) { while ( have_posts() ) { the_post(); ?>