I have a static page which runs two loops but pagination doesn\'t work on the second loop.
<第一个循环显示页面的静态内容,第二个循环显示最后3篇博客文章,分页显示,将/page/2添加到url,但始终显示相同的3篇文章。为什么这不符合预期?
First loop: display the static content
if (have_posts()) : while (have_posts()) : the_post();
the_content(\'<p class="serif">Read the rest of this page »</p>\'); ?>
endwhile; endif;
Second loop: shows the last 3 posts and paginationglobal $more;
$more = 0;
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query(array(\'post_type\'=>\'post\',\'post_status\'=>\'publish\',\'showposts\'=>3,\'paged\'=>$paged));
while ($wp_query->have_posts()) : $wp_query->the_post();
the_content();
endwhile;
next_posts_link();
previous_posts_link();
SO网友:s_ha_dum
您没有设置$paged
变量,至少不在发布的代码中。
Per the Codex, 您需要这样做:
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
。。。在尝试使用之前
$paged
变量也就是说,它需要排在这一行之前:
$wp_query->query(array(\'post_type\'=>\'post\',\'post_status\'=>\'publish\',\'showposts\'>3,\'paged\'=>$paged));
还有,请注意,这是什么——
php the_content();
? 这将触发一个错误。为什么你有
php
那里