Friday, October 8, 2010

Wordpress - wp_paginate - Error 404 on pagination when changing posts_per_page on query_posts

To fix 404 page errors while using wp_paginate() in wordpress.
while going to sample-page/page/2 will leads to 404 as the 'page' will be taken as a category.

SO we need to use the 'page' as a query string while using query_posts

Steps 1:
--------
Open the php page (sample: test.php) in a text editor and add this code:

<code><?php
global $query_string;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts($query_string.'&paged='.$paged.'&posts_per_page=3'); 
// for getting results of 3rd page

?>

Step:2
------

</code>
  1. Login as the admin
  2. Go to the Settings.
  3. Go to the Reading.
  4. Change the Blog pages show at most to any number. Ex, 5.
  5. Save the changes.
  6. View the blog

wordpress404

If everything goes well, your pagination should be working perfectly fine without you changing any code.

Popular Posts