2

Any way to limit the number of pages that are created automatically by paging? I would limit to five pages in all, authors, tags, categories ... Ex: "site.com/tag/news/page/5", "...author/admin/page/5."

Thanks.

3
  • In the backend? Jun 23, 2012 at 12:43
  • Hi @Rutwick Gangurde In the frontend.
    – BobGCA2
    Jun 23, 2012 at 12:46
  • The paging can be controlled if you can edit the theme files. Jun 23, 2012 at 12:52

1 Answer 1

4

This seem to work. Put in your functions.php:

add_filter('pre_get_posts', 'limit_pages');
function limit_pages($query) {

    $query->max_num_pages = 5;
    if ($query->query_vars['paged'] > 5) {
        $query->query_vars['paged'] = 5;
        $query->query['paged'] = 5;
    }

    return $query;
}

But I guess you would still need some workaround for posts pagination and authors. Hope it helps you a little.

5
  • thanks for trying @Vinicius Massuchetto, but this function has not changed.
    – BobGCA2
    Jun 23, 2012 at 12:40
  • Well.. it is working here. Did you try accessing page/6/, page/7/, page/8/? They should all look the same. Jun 23, 2012 at 12:45
  • Please note that this way all your posts are still directly accessible, we're just dealing with pagination here. Jun 23, 2012 at 12:46
  • The comment is fine. Just leave it there. =D Jun 23, 2012 at 13:09
  • Oh, sorry @Vinicius Massuchetto, now it is working. Now we need to adapt my function to display pagination links only to the number 5 (Pages: 1 2 3 4 5). Chosen to best response. Thanks!
    – BobGCA2
    Jun 23, 2012 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.