The following code was mentioned from one of the commentors, however it is breaking the pagination. Any corrections please

    include(TEMPLATEPATH. '/includes/headline.php'); rewind_posts();
    if (have_posts()) 
    echo '<div class="gridrow clear">';
    while (have_posts()) : the_post();
    global $post;
    query_posts( $query_string .'&posts_per_page=5' );
    include(TEMPLATEPATH. '/includes/loop.php');
    $q = $wp_query->current_post;
    $maxq = tj_current_postnum();
    if($q < $maxq-1 && is_int(($q+1)/2)) echo '</div><div class="gridrow clear">';
    echo '</div> <!--end .gridrow-->';
    } else { 
    include(TEMPLATEPATH. '/includes/not-found.php'); 
    if ( $wp_query->max_num_pages > 1 ) tj_pagenavi();?>
  • I tried changing the value of $maxq to 5 (to limit to only 5 posts) but it doesn't work. Any help on this please
    – Sledge81
    May 16, 2011 at 9:37
  • Based on the recommendations, this is the modified code.. but it continues to break pagination.
    – Sledge81
    Jul 7, 2011 at 12:04
  • Well, i've pretty much exhausted all the options. Came across this resource link and also few of the additional tips mentioned at the end of the post.. but nothing seems to be fixing the pagination problem
    – Sledge81
    Jul 7, 2011 at 14:17

2 Answers 2


You need to tell Wordpress to get only 5 posts per page. The parameter to do this is posts_per_page. You should use query_posts() function before your have posts as in the following example.

   // your includes and stuff

   global $query_string;

   query_posts( $query_string . '&posts_per_page=5' );

   // now your have_posts
   if ( have_posts() ) {
       // list the posts
   } else {
       // not found msg here..
  • 1
    the simple query_posts( 'posts_per_page=5' ); will cause problems with pagination; expand it to: global $query_string; query_posts( $query_string .'&posts_per_page=5' );
    – Michael
    May 16, 2011 at 10:00
  • Thanks for your help so far. This is how my code looks now and nothing happens (Sorry, i'm not a php expert) any suggestions <?php include(TEMPLATEPATH. '/includes/headline.php'); global $query_string; query_posts( $query_string .'&posts_per_page=5' ); Rest of code follows
    – Sledge81
    May 16, 2011 at 10:05
  • Ignore my previous message... This fixed.. Thanks Hameed and Michael
    – Sledge81
    May 16, 2011 at 10:08
  • @Michael Thanks for the correction, made the corrections in above answer. May 16, 2011 at 10:18
  • I just noticed that the above code does break the pagination.
    – Sledge81
    Jul 7, 2011 at 12:04

The code you have at the top of this page has a nested loop. Is that what you want?

The following code would normally go above the while loop for "the_post()"

query_posts( $query_string .'&posts_per_page=5' );

This may not be your issue, but I thought it may help.

  • Thanks Daniel.. but it still continues to break the pagination even after using the code mentioned above.. placed above the 'while (have_posts... function
    – Sledge81
    Jul 7, 2011 at 12:51
  • Have you changed the number of posts per page in the WP UI? In Settings->Reading. And can we see a link to the site. And it is not clear to me what you mean when you say "pagination is broken". Is there no pagination, are you getting a 404 error, etc.? Jul 7, 2011 at 13:37
  • Yes, 404 error beyond page 8 (404 starts from page 9 onwards). In Wp settings, the default is set to 10 posts, but it in particular category template the post is limited to 5.
    – Sledge81
    Jul 7, 2011 at 13:43
  • How many posts do you have? Jul 7, 2011 at 14:00
  • 104 posts in this particular category
    – Sledge81
    Jul 7, 2011 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.