doujubeng2942 2014-10-03 15:51
浏览 35

Wordpress single.php第二次查询分页

I created a single.php Wordpress template file to show standard WP Posts.

This is the truncated version of the code:

<?php 
// First (Main Content) Loop
if (have_posts()) : 
  while (have_posts()):the_post();  
  ?>

  <div class="entry-content">
    <h2><?php the_title(); ?></h2>
    <?php the_content(); ?>
  </div>    

  <?php 
  endwhile;
endif;
wp_reset_postdata();
?>

<?php
// Second (Related Posts) Loop

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args=array(
  'category__in' => 3,
  'posts_per_page'=> 4,
  'paged' => $paged
);

$temp = $wp_query;
$wp_query= null;
$wp_query = new wp_query($args);

if( $wp_query->have_posts() ) :
  while ($wp_query->have_posts()) :
    $wp_query->the_post();
    ?>

    <div class="entry-content">
        <h2><?php the_title(); ?></h2>
        <?php the_content(); ?>
    </div>  

  <?php
  endwhile; 

  echo '<div id="navigation">'.get_next_posts_link('Load More').'</div>'; 

endif;
}

$wp_query = null; 
$wp_query = $temp;
?>

The 4 related posts are generated as expected and the get_next_posts_link generates a link to /post-name/page/2.

I'm using Paul Irish's Infinite Scroll plugin to load page/2's posts into the container (Which is working fine on the archive- and index.php pages on the site).

Unfortunately when you click get_next_posts_link the same 4 posts are appended to the container.

Any ideas how to get this to work? I've tried a lot of other solutions on StackOverflow but so far none have worked.

Any help appreciated, cheers.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算