Title: Pagnitation stops working after adding a second loop
Last modified: August 21, 2016

---

# Pagnitation stops working after adding a second loop

 *  Resolved [unlimit3d1](https://wordpress.org/support/users/unlimit3d1/)
 * (@unlimit3d1)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/stops-working-after-adding-a-second-loop/)
 * Hi
    I added successfully a secondary loop in my theme in home.php, but after 
   that the pagnitation stop working , can any body helps me
 * this is the code i use:
 * _[please mark any posted code – [http://codex.wordpress.org/Forum\_Welcome#Posting\_Code](http://codex.wordpress.org/Forum_Welcome#Posting_Code)–
   the code below is partially broken]
 *     ```
       <?php query_posts('category_name=news &posts_per_page=3');?>
       <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
       	<?php the_title(); ?>
       	<?php the_excerpt ();?>
       <?php endwhile; endif; ?>
   
       <?php wp_reset_query(); ?>
   
       <?php query_posts('cat=-13,-15');?>
       <?php if(have_posts()): while(have_posts()):the_post();?>
       	<?php the_time('F j, Y'); ?>
       	<?php $category = get_the_category(); if($category[0]){echo '<a>term_id ).'">'.$category[0]->cat_name.'</a>';}?>
       	<?php comments_popup_link( 'Няма коментари', '1 коментар', '% коментара', 'comments-link', 'Коментарите за тази публикация са изключени');?>
       	<?php if (function_exists('has_post_thumbnail') && has_post_thumbnail()) the_post_thumbnail();?>
       	<?php the_title(); ?>
       	<?php the_excerpt ();?>
       	<?php endwhile; endif;?>
       <?php posts_nav_link(); ?>
       ```
   

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/stops-working-after-adding-a-second-loop/#post-4236774)
 * use WP_Query for second loops;
 * [http://wordpress.stackexchange.com/questions/1753/when-should-you-use-wp-query-vs-query-posts-vs-get-posts?rq=1](http://wordpress.stackexchange.com/questions/1753/when-should-you-use-wp-query-vs-query-posts-vs-get-posts?rq=1)
 *  Thread Starter [unlimit3d1](https://wordpress.org/support/users/unlimit3d1/)
 * (@unlimit3d1)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/stops-working-after-adding-a-second-loop/#post-4236862)
 * Thanks for the replay but, can you be a little more specific how exactly to do
   that… i am a new to wordpress development
 * When i use this
    `<?php $my_query = new WP_Query('cat=-13,-15');?>` page navigation
   works but displays categories which i don’t want to display
 *  [Borko](https://wordpress.org/support/users/media-x/)
 * (@media-x)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/stops-working-after-adding-a-second-loop/#post-4236869)
 * What about changing Category ID’s ?
 *  Thread Starter [unlimit3d1](https://wordpress.org/support/users/unlimit3d1/)
 * (@unlimit3d1)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/stops-working-after-adding-a-second-loop/#post-4236871)
 * No, it’s not that…
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/stops-working-after-adding-a-second-loop/#post-4236872)
 * what are you trying to paginate?
    – the first loop or the second loop?
 * what is the current full code of the second loop?
 *  Thread Starter [unlimit3d1](https://wordpress.org/support/users/unlimit3d1/)
 * (@unlimit3d1)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/stops-working-after-adding-a-second-loop/#post-4236874)
 * Trying to paginate the second loop.
    The code looks like this:
 *     ```
       <?php query_posts('category_name=news &posts_per_page=3');?>
       <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
       	<?php the_title(); ?>
       	<?php the_excerpt ();?>
       <?php endwhile; endif; ?>
   
       <?php wp_reset_query(); ?>
       <?php $my_query = new WP_Query('cat=-13,-15');?>
       <?php if(have_posts()): while(have_posts()):the_post();?>
       	<?php the_time('F j, Y'); ?>
       	<?php $category = get_the_category(); if($category[0]){echo '<a>term_id ).'">'.$category[0]->cat_name.'</a>';}?>
       	<?php comments_popup_link( 'Няма коментари', '1 коментар', '% коментара', 'comments-link', 'Коментарите за тази публикация са изключени');?>
       	<?php if (function_exists('has_post_thumbnail') && has_post_thumbnail()) the_post_thumbnail();?>
       	<?php the_title(); ?>
       	<?php the_excerpt ();?>
       	<?php endwhile; endif;?>
       <?php posts_nav_link(); ?>
       ```
   
 * Paginate works now, but displays categories which i don’t want to display.
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/stops-working-after-adding-a-second-loop/#post-4236876)
 * > Trying to paginate the second loop.
 * in this case, try to switch the code for the loops; i.e. use `WP_Query()` for
   the first loop, and `query_posts()` for the second loop;
    example:
 *     ```
       <?php $my_query = new WP_Query('category_name=news &posts_per_page=3');?>
       <?php if ( $my_query->have_posts() ) : while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
       	<?php the_title(); ?>
       	<?php the_excerpt ();?>
       <?php endwhile; endif; wp_reset_postdata(); ?>
   
       <?php query_posts('cat=-13,-15&paged='.get_query_var('paged'));?>
       <?php if(have_posts()): while(have_posts()):the_post();?>
       	<?php the_time('F j, Y'); ?>
       	<?php $category = get_the_category(); if($category[0]){echo '<a>term_id ).'">'.$category[0]->cat_name.'</a>';}?>
       	<?php comments_popup_link( 'Няма коментари', '1 коментар', '% коментара', 'comments-link', 'Коментарите за тази публикация са изключени');?>
       	<?php if (function_exists('has_post_thumbnail') && has_post_thumbnail()) the_post_thumbnail();?>
       	<?php the_title(); ?>
       	<?php the_excerpt ();?>
       	<?php endwhile; endif;?>
       <?php posts_nav_link(); ?>
       ```
   
 *  Thread Starter [unlimit3d1](https://wordpress.org/support/users/unlimit3d1/)
 * (@unlimit3d1)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/stops-working-after-adding-a-second-loop/#post-4236878)
 * Works perfectly, thank you very much 🙂

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

The topic ‘Pagnitation stops working after adding a second loop’ is closed to new
replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 8 replies
 * 3 participants
 * Last reply from: [unlimit3d1](https://wordpress.org/support/users/unlimit3d1/)
 * Last activity: [12 years, 7 months ago](https://wordpress.org/support/topic/stops-working-after-adding-a-second-loop/#post-4236878)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
