尽管完全遵循 the example in the codex ,我点击分页时到达的页面next
链接( http://localhost:3000/my_project/news/page/2/ )不存在(“找不到页面”)。
为什么?
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; echo 'paged = ' . $paged;
$regular_posts = new WP_Query('posts_per_page=3&paged=' . $paged);
while ($regular_posts->have_posts()): $regular_posts->the_post();
the_title();
endwhile;
echo get_next_posts_link('Older Entries', $regular_posts->max_num_pages);
此代码包含在我的“home.php”模板中,管理我在仪表板中创建并在“阅读设置”中设置为“帖子页面”的“新闻”页面。
最佳答案
静态主页与存档略有不同,因为它 page
参数而不是 paged
.
Codex Pagination page 包含用于静态主页的此代码,它实际上适用于所有情况(即甚至存档页面),因为它检查两个参数:
if ( get_query_var( 'paged' ) ) { $paged = get_query_var( 'paged' ); }
elseif ( get_query_var( 'page' ) ) { $paged = get_query_var( 'page' ); }
else { $paged = 1; }
但是,如果您只需要它在主页上工作,将 $paged 变量的代码更改为以下内容也应该有效:
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
关于wordpress - 分页功能在 WordPress 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46469514/