Fix for pagination in categories
-
I noticed lots of ppl (including myself) are having problems with pagination in categories, where the first page would work, but the second page, “page/2/” would send you to the 404 – page.
After googling around for 20 minutes I only found bits of the solution, which I merged together and got it working! Do like this:
1. You don’t need to change anything in the Dashboard -> Reading Settings as some has suggested. Put it back to how it was.
2. In your query_posts, remove the “post_per_page” limitation, since sin category.php this doesn’t work when you want to generate pages.
so in my case
query_posts(array ('cat' => $current_cat_id, "paged" => "$paged", "posts_per_page" => "1", ));
becomes
query_posts(array ('cat' => $current_cat_id, "paged" => "$paged" ));
3. Copy the following lines and put them in your functions.php. In the last you set the numbers of posts you want to show for each page:
add_action( 'parse_query', 'category_posts_per_page', 10, 1 ); function category_posts_per_page( $q_obj ) { if( is_category() ) $q_obj->query_vars['posts_per_page'] = 1; // Change this example value }
Now, techically, pagination is working, but one (big) problem is remaining.
a) Lets say you are using customized permalinks, like I am doing; the classic: /%category%/%postname%/.
b) And lets pretend you have category called Music.
The problem you will be having is that pagination WILL work if you type: (your_site_url)/categories/music, but if will fail when wordpress sends the viewer to (your_site_url)/music directly, which wordpress loves to do.Solution?
4. This one was hard to find, but it’s easy and works! Just download and install the Category Pagination Fix plugin .
Now, suddenly, pagination is working in categories no matter url structure. Yeah! ??
- The topic ‘Fix for pagination in categories’ is closed to new replies.