[resolved] Different number of posts on category page 1 (37 posts)

  1. keesiemeijer
    Posted 4 years ago #

    Ah, I think I found a solution. put this in your theme's functions.php and change the category ID in is_category(1) to the (news category) ID where you want 5 posts and 20 posts: http://pastebin.com/SSxWvMnd

    and use this for your cat-news.php: http://pastebin.com/WEjruURY
    This is the only code I added to it:

            global $wp_query;
            $first_page_total= 5; // total number of posts on first page
            $paginated_total = 20;
            $found_posts = $wp_query->found_posts;
            $pages = 1 + ceil(($found_posts - $first_page_total) / $paginated_total);
            $wp_query->max_num_pages = $pages;
  2. greencode
    Posted 4 years ago #

    So sorry not to get back to you about this. I've been fighting fires with fires at work!

    I tried exactly as you mentioned in your previous message but I get the following error when attempting to view that category:

    Fatal error: Call to undefined method WP_Query::is_main_query() in /home/mysite/public_html/dev/wp-content/themes/mytheme/functions.php on line 16

    Any ideas?

  3. greencode
    Posted 4 years ago #

    Hi. I've also got a news category that has only 6 posts but what's happening is the first 5 are showing on the first page - as they should - and the page numbers are showing as 1 and 2 - again correct - but if I click page 2 I get a Page Not found. I then just increased the number of posts showing on the home page from 5 to 10 and all posts are then showing but the page numbers 1 and 2 are still showing!

    Really lost with this one.

  4. keesiemeijer
    Posted 4 years ago #

    Try it with this in your functions.php: http://pastebin.com/jZRS5Yq5
    It will remove the Fatal error.

  5. greencode
    Posted 4 years ago #

    Thank you sooooooo much for this. It works absolutely perfectly. Really appreciate your constant help on this issue. I wouldn't have had a clue where to begin with this.

  6. keesiemeijer
    Posted 4 years ago #

    You're welcome. When you update your install to 3.3 or higher (you should) you can use this in functions.php: http://pastebin.com/SSxWvMnd

    I'm glad you got it resolved.

  7. greencode
    Posted 4 years ago #

    Great, thanks again.

Topic Closed

This topic has been closed to new replies.

About this Topic