NEXT_POSTS_LINK返回第一页的相同内容

时间:2013-04-26 作者:John

分页似乎工作正常。。。我有21个帖子。。。它将转到3页。。。然而每页显示10篇帖子,内容与第一页相同。。。。

<?php
$temp = $wp_query;
$wp_query= null;

$args = array(
    \'post_type\' => \'a-reports\',
    \'post_status\' => \'publish\'
);
$wp_query = new WP_Query( $args );
if ( $wp_query-> have_posts() )
{
while ($wp_query->have_posts()) : $wp_query->the_post(); 
?>
<a target="blank" href="<?php the_permalink(); ?>">Report</a>
<?php
endwhile;

<?php next_posts_link(\'Older Entries »\'); 

//clear again
$wp_query = null;
//reset
$wp_query = $temp;
?>

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

整齐to get pagination working 对于二次循环,您必须通过$paged 参数到WP_Query, 另一方面,查询不知道要加载哪一组帖子,每次都会加载第一组,第1页。我通过添加\'paged\' => $paged 内部$args = array();

$args = array(
    \'post_type\' => \'a-reports\',
    \'post_status\' => \'publish\',
    \'paged\' => $paged,
)

结束

相关推荐

Ending Pagination loop in PHP

<div id=\"pagination\"> <div class=\"prev\"><?php next_posts_link(\'&larr;\') ?></div> <div class=\"pages\"> <?php global $wp_query; $big = 9999;