Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
In the backend? –  Rutwick Gangurde Jun 23 '12 at 12:43
    
Hi @Rutwick Gangurde In the frontend. –  BóbGCA Jun 23 '12 at 12:46
    
The paging can be controlled if you can edit the theme files. –  Rutwick Gangurde Jun 23 '12 at 12:52
add comment

1 Answer

up vote 2 down vote accepted

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.

share|improve this answer
    
thanks for trying @Vinicius Massuchetto, but this function has not changed. –  BóbGCA Jun 23 '12 at 12:40
    
Well.. it is working here. Did you try accessing page/6/, page/7/, page/8/? They should all look the same. –  vmassuchetto Jun 23 '12 at 12:45
    
Please note that this way all your posts are still directly accessible, we're just dealing with pagination here. –  vmassuchetto Jun 23 '12 at 12:46
    
The comment is fine. Just leave it there. =D –  vmassuchetto Jun 23 '12 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! –  BóbGCA Jun 23 '12 at 13:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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