It’s a custom theme based on the toolbox theme. Here’s what I use for my cat-news.php category page to display the News category items.
[Code moderated as per the Forum Rules. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]
Two problems now…
1. I have the first post styled differently to the other posts, so unsure how to include that in the code you kindly provided.
2. Just quickly adding your code appears to work but then if I click on the last page in the pagination then I get a page not found.
Thanks once again for your help with this – I really wouldn’t know where to start with this. I’ve trawled the internet high and low and couldn’t find anything similar.
Your code got modererated can you paste and submit the full code of cat-news.php into a pastebin.com and post the link to it here? see the Forum Rules for posting code and using the pastebin.
Ahh, thanks for the heads up.
Here’s the code: http://pastebin.com/Ed9yTa7a
Maybe this works [untested]: http://pastebin.com/9UVeHvxN
It’s very strange. The page numbers show correctly but clicking on the last page number just takes me to the page but with a Page not found, even though the penultimate page is not the end of the post count i.e. there’s 16 posts missing from the end which should be on the last page?!
Have you tried it with pastebin in my last post?
Hi. Yep, that’s the one I used i.e. replacing all the content of my cat-news.php file with the code you provided. It’s very odd that the last page number exists but there’s no page to be found even though there should be another 16 posts to display?
On my testserver this works as expected, very strange. I simplified it a bit: http://pastebin.com/hMBkueXp
Maybe this works.
Just done a little bit of testing – using your latest code and here’s what’s happening…
If I edit the following code:
$paginated_total = 20
to the same amount that shows in the Admin > Reading > Blog pages show at most total then all works well i.e. 5 posts on first page and 20 on subsequent pages. If, however, I set the code above to something less than is specified in the WP admin then the last page doesn’t work. i.e.
paginated_total = 20 / reading settings = 20 > Works correctly
paginated_total = 19 / reading settings = 20 > Page not found
paginated_total = 21 / reading settings = 20 > Works correctly
Your reading settings shouldn’t influence this. Try changing this:
$the_query = new WP_Query( $args1 );
to this:
wp_reset_postdata();
$the_query = new WP_Query( $args1 );
or to this:
wp_reset_query();
$the_query = new WP_Query( $args1 );
Also, did you remove the function from your theme’s functions.php. And also look in there if your theme is adding filters to category pages.
It really is very odd. I’ve checked the functions.php file and there’s nothing in there that would be having any influence on things. Tried those bits of code you mentioned and they all basically worked in the same way but didn’t help with the last page problem.
Very strange indeed!
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:
<?php
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;
?>