This code will only load 5 posts on the first category page and 20 on subsequent pages. Put this in your theme’s functions.php: http://pastebin.com/izVjUE5e
Thanks for this. I added that to my functions and I got the following error when viewing the page:
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 215
215 appears to be this line:
if (!is_admin() && $query->is_main_query()){
Any ideas?
If I remove the code I mentioned in the my previous post then all works well but I’m presuming that’s there for a reason.
What version of WordPress are you using?
the function is_main_query() was introduced in WordPress 3.3.0 that’s why it doesn’t work. Why don’t you update to the latest version?
I will, but there’s a number of plugins that I need to ensure will work on the current version of WP.
Is it okay to use that code without the the main_query part of it?
As I mentioned, it seems to work okay without it but then again I’ve only checked a page or two.
Is it okay to use that code without the the main_query part of it?
No.
This will work with older WordPress versions:
change this:
if (!is_admin() && $query->is_main_query()){
to this:
global $wp_the_query;
if (!is_admin() && ($wp_the_query === $query )){
Thanks again for this. The only trouble with this now is that the pagination is incorrect. For example I only have 6 pages for the category but on the first page it’s showing that I have 20.
I’m using the following code at the bottom of my page, if that’s any help:
<?php /* Display navigation to next/previous pages when applicable */ ?>
<?php if ( $wp_query->max_num_pages > 1 ) : ?>
<nav id="nav-below">
<?php wp_pagenavi(); ?>
</nav><!-- #nav-below -->
<?php endif; ?>
Yeah I just realized that it doesn’t work with wp_pagenavi. I have to figure that one out.
Thanks, really appreciate your help with this.
Forgive me. I’m a little lost with what solution on that page I am looking at? Do I still keep the function in place from above?
Do I still keep the function in place from above?
no, remove that function. and use something like this in your theme’s category.php: http://pastebin.com/EsfqXTYz
What theme do you use?