Title: Pagination loop issue
Last modified: August 19, 2016

---

# Pagination loop issue

 *  Resolved [localretard](https://wordpress.org/support/users/localretard/)
 * (@localretard)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/pagination-loop-issue/)
 * I have the reading settings in the admin set to only show 2 posts. I also have
   a query in the global loop to exclude some categories:
 * `query_posts("&cat=-179,-4,-70,-19" );` This query will be on the front page
 * and I’m trying to continue that loop on other pages because I only want that 
   those specific posts to show and I want more than just two to show. So the code
   is:
 * `query_posts($query_string . "&posts_per_page=10" );`
 * Now what is happening is the frontpage works, however it seems to always get 
   screwed up during the pagination. What am I doing wrong?
 * Here is the simplistic version of the code:
 *     ```
       <?php if ( $paged < 2 ) { // Do stuff specific to first page?>
   
       <?
       query_posts("&cat=-179,-4,-70,-19" );
       while ( have_posts() ) : the_post();
   
       ?>
   
       <?php the_title(); ?>
   
       <?php endwhile; ?>
   
       <? } else { ?>
   
       <?
   
       query_posts($query_string . "&posts_per_page=10" );
       while (have_posts()) : the_post();
       ?>
   
       <?php the_title(); ?>
   
       <?php endwhile; ?>
   
       <? } ?>
       ```
   

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/pagination-loop-issue/#post-1954707)
 * Here is an article I wrote with a code example of how to implement a [short first page](http://wordpress.mcdspot.com/2010/04/01/short-first-page/).
 *  Thread Starter [localretard](https://wordpress.org/support/users/localretard/)
 * (@localretard)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/pagination-loop-issue/#post-1954876)
 * Thanks that actually did help.
 * For anyone else with the same or similar issue, I had to customize it around 
   my paging code as so:
 *     ```
       <?php
        $max_first_page = 2;  // Show this many posts on front page
             $args = $wp_query->query;
             $args['caller_get_posts'] = 1; // Using stickies messes up the count
             $args['cat'] = '-179,-4,-70,-19';
             $page = (get_query_var('paged')) ? get_query_var('paged') : 1;
             $posts_per_page = get_query_var('posts_per_page');
             $posts_to_skip = $posts_per_page - $max_first_page;
             if ($page == 1) {
                $max_posts = $max_first_page;
             } else {
                $max_posts = $posts_per_page;
                $args['offset'] = (($page - 1) * $max_posts)- $posts_to_skip;
             }
             query_posts($args);
             if ($wp_query->max_num_pages < ceil(($wp_query->found_posts + $posts_to_skip)/$posts_per_page))
               ++$wp_query->max_num_pages;
             $counter = 0;
             ?>
   
       <? if ( $paged < 2 ) { // Do stuff specific to first page?>
   
       while (have_posts()) : the_post();
                if (++$counter > $max_posts) continue;
   
       <? the_title(); ?>
       		<br/>
       <? endwhile; } else { ?>
   
       <? while (have_posts()) : the_post(); if (++$counter > $max_posts) continue; ?>
   
       <? the_title(); ?>
       			<br/>
       <? endwhile; } ?>
       ```
   

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Pagination loop issue’ is closed to new replies.

## Tags

 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [multiple](https://wordpress.org/support/topic-tag/multiple/)
 * [pagination](https://wordpress.org/support/topic-tag/pagination/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [localretard](https://wordpress.org/support/users/localretard/)
 * Last activity: [15 years, 2 months ago](https://wordpress.org/support/topic/pagination-loop-issue/#post-1954876)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
