使用分页/foo/page/2/重写到给定类别的帖子,第2页

时间:2021-11-11 作者:Basj

add_action(\'init\',  function() {
    add_rewrite_rule(\'^foo\', \'index.php?category_name=category1\', \'top\');
});
工作并允许example.com/foo/ 显示来自category1.

但是分页不起作用。

本页底部有一个链接,显示;“旧帖子”;,然后重定向到example.com/foo/page/2/.

Question: how to have example.com/foo/page/2/ display all the posts from category1, page 2?(无第三方插件)

1 个回复
SO网友:Basj

解决方法:

add_rewrite_rule(\'^foo/page/([0-9]+)/?$\', \'index.php?category_name=category1&paged=$matches[1]\', \'top\');    
add_rewrite_rule(\'^foo\', \'index.php?category_name=category1\', \'top\');
这两行之间的顺序很重要。

另请参见Permalink/Pagination issue: Category base name same as page name.