admin管理员组

文章数量:1279182

This

add_action('init',  function() {
    add_rewrite_rule('^foo', 'index.php?category_name=category1', 'top');
});

works and allows example/foo/ to display all the posts from category1.

But then the pagination doesn't work.

There is a link on the bottom of this page that shows "Older posts", and that redirects to example/foo/page/2/.

Question: how to have example/foo/page/2/ display all the posts from category1, page 2? (without a third party plugin)

This

add_action('init',  function() {
    add_rewrite_rule('^foo', 'index.php?category_name=category1', 'top');
});

works and allows example/foo/ to display all the posts from category1.

But then the pagination doesn't work.

There is a link on the bottom of this page that shows "Older posts", and that redirects to example/foo/page/2/.

Question: how to have example/foo/page/2/ display all the posts from category1, page 2? (without a third party plugin)

Share Improve this question asked Nov 11, 2021 at 20:48 BasjBasj 8510 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Solved with:

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');

The order between these two lines here is important.

See also Permalink/Pagination issue: Category base name same as page name.

本文标签: phpRewrite with pagination foopage2 to posts of a given categorypage 2