Title: Multiple Loops   Additional classes   Pagination  help
Last modified: August 20, 2016

---

# Multiple Loops Additional classes Pagination help

 *  Resolved [streetrose](https://wordpress.org/support/users/streetrose/)
 * (@streetrose)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/multiple-loops-additional-classes-pagination-help/)
 * I have been coding themes for the past years but I’m not really an expert in 
   php. I hope someone can help me about this problem:
 * I have four loops in index.php
 * 1st: featured category posts carousel (which is already working way before)
 * 2nd: Certain cat post, 1 post_per_page, with additional class in most parent 
   div
 * 3rd: Certain cat posts, 2 post_per_page, with additional class in most parent
   div
 * 4th: The rest of the posts, with additional class in most parent divs, hould 
   do_not_duplicate posts from above category except for featured
 * then I want the 4th loop to be paginated — like page/2/ will show the next page
   of the rest of the posts (aka recent posts) in the 4th loop.
 * Here is my code
 *     ```
       <!-- start content -->
       <div id="content">
       	<?php if(is_home() && !is_paged()): ?>
           <?php // Featured posts go here.
           include (TEMPLATEPATH . "/featured.php"); ?>
           <?php endif;?>
           <?php if(is_home() && !is_paged()): ?>
           <div id="highlightcat1">
           	<h3 class="head">Latest Projects <a title="More Projects Updates" href="http://ygladies.com/category/ygladies/projects">more+</a></h3>
       		<?php if( $themesbyrozeh_settings['highlighted_cat1'] ) : ?>
               <?php query_posts('posts_per_page=1&cat=' . $themesbyrozeh_settings['highlighted_cat1'] ); ?>
               <?php while (have_posts()) : the_post(); ?>
               <?php $do_not_duplicate[] = $post->ID; ?>
           	<div class="post ptop red">
                   <div class="feat">
                       <?php
                       // Must be inside a loop.
   
                       if ( has_post_thumbnail() ) {
                           the_post_thumbnail('ptop');
                       }
                       else {
                       // nothing here
                       }
                       ?>
                       <span class="date"><?php the_time('d F y') ?></span>
                   </div>
                   <div class="entry">
                           <div class="entryinfo">
                               <?php edit_post_link('Edit', '<span class="edit">', '</span> -'); ?> <span class="author"><?php the_author() ?></span> - <span class="sdate"><?php the_time('d/m/y') ?></span> - <span class="comment_count"><?php comments_popup_link('0 Comments', '1 Comment', '% Comments'); ?></span>
                               <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
                           </div>
                           <p><?php echo limit_words(get_the_excerpt(), '30'); ?>.</p>
                           <a class="readmore" href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">Read More &rarr;</a>
                   </div>
               </div>
               <?php endwhile; ?>
               <?php endif; ?>
               <?php wp_reset_query(); ?>
           </div>
           <?php endif;?>
   
           <?php if(is_home() && !is_paged()): ?>
           <div id="highlightcat2">
           	<h3 class="head">Latest SNS Updates <a title="More SNS Updates" href="http://ygladies.com/category/snsupdates">more+</a></h3>
       		<?php if( $themesbyrozeh_settings['highlighted_cat2'] ) : ?>
               <?php query_posts('posts_per_page=2&cat=' . $themesbyrozeh_settings['highlighted_cat2'] ); ?>
               <?php while (have_posts()) : the_post(); ?>
               <?php
               $extra_classes = array('orange','green','blue','indigo','violet','pink','red');
               $extra_class = $extra_classes[$wp_query->current_post%count($extra_classes)];
               ?>
               <?php $do_not_duplicate[] = $post->ID; ?>
           	<div class="post ptop2 <?php echo $extra_class; ?> clearfix">
                   <div class="feat">
                       <?php
                       // Must be inside a loop.
   
                       if ( has_post_thumbnail() ) {
                           the_post_thumbnail();
                       }
                       else {
                       // nothing here
                       }
                       ?>
                       <span class="date"><?php the_time('d F y') ?></span>
                   </div>
                   <div class="entry">
                           <div class="entryinfo">
                               <?php edit_post_link('Edit', '<span class="edit">', '</span> -'); ?> <span class="author"><?php the_author() ?></span> - <span class="comment_count"><?php comments_popup_link('0 Comments', '1 Comment', '% Comments'); ?></span>
                               <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
                           </div>
                           <p><?php echo limit_words(get_the_excerpt(), '30'); ?>.</p>
                           <a class="readmore" href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">Read More &rarr;</a>
                   </div>
               </div>
               <?php endwhile; ?>
               <?php endif; ?>
               <?php wp_reset_query(); ?>
           </div>
       	<?php endif;?>
           <h3 class="head">Recent Posts</h3>
           <div id="entries" class="clearfix">
       		<?php query_posts(array('post__not_in'=>$do_not_duplicate));
       		 if (have_posts()) : while (have_posts()) : the_post();
       		 ?> 
   
       		<?php
               $extra_classes = array('blue','indigo','violet','pink','red','orange','green');
               $extra_class = $extra_classes[$wp_query->current_post%count($extra_classes)];
               ?>
   
               <!-- start entry post -->
               <div class="post pfloat <?php echo $extra_class; ?>" id="post-<?php the_ID(); ?>">
                   <div class="entry">
                       <div class="feat">
       					<?php
                           // Must be inside a loop.
   
                           if ( has_post_thumbnail() ) {
                               the_post_thumbnail();
                           }
                           else {
                           // nothing here
                           }
                           ?>
                           <span class="date"><?php the_time('d F y') ?></span>
                       </div>
                       <div class="entryinfo">
                           <?php edit_post_link('Edit', '<span class="edit">', '</span> -'); ?> <span class="author"><?php the_author() ?></span> - <span class="comment_count"><?php comments_popup_link('0 Comments', '1 Comment', '% Comments'); ?></span>
                           <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
                       </div>
                       <p><?php echo limit_words(get_the_excerpt(), '30'); ?>.</p>
                   </div>
               </div>
               <!-- end entry post -->
   
               <?php endwhile; ?>
               <?php else : ?>
   
               <div class="post">
                   <div class="entry">
                       <h2>Not Found</h2>
                       Sorry, but you are looking for something that isn't here.
                   </div>
               </div>
   
               <?php endif; ?>
               <?php wp_reset_query(); ?>
           </div>
           <div id="pagi">
               <?php previous_posts_link('&larr; Previous') ?><?php rozehtheme_pagination(); ?><?php next_posts_link('Next &rarr;') ?>
           </div>
       </div>
       <!-- end content -->
       ```
   
 * I thought I made it work (the classes are there and there are no duplicate posts
   but when I went to page/2/, it’s displaying the same posts in loop 4.
 * I hope anyone can help me here. I will forever be grateful. 🙂

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

 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/multiple-loops-additional-classes-pagination-help/#post-3137763)
 * Try to use `new WP_Query( $args );` for the secondary (first three) loops and
   use [wp_reset_postdata()](http://codex.wordpress.org/Function_Reference/wp_reset_postdata)
   after each secondary loop.
 * [http://codex.wordpress.org/Function_Reference/WP_Query#Interacting_with_WP_Query](http://codex.wordpress.org/Function_Reference/WP_Query#Interacting_with_WP_Query)
 * And add the paged parameter to the main query:
    [http://codex.wordpress.org/Pagination#Adding_the_.22paged.22_parameter_to_a_query](http://codex.wordpress.org/Pagination#Adding_the_.22paged.22_parameter_to_a_query)
 *  [@Raj](https://wordpress.org/support/users/rajeshtandonrocketmailcom/)
 * (@rajeshtandonrocketmailcom)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/multiple-loops-additional-classes-pagination-help/#post-3137880)
 * i m relatively having the same problem
    I have created a blog on which i want
   to show two category list and i have successed to do half of that know the problem
   is that both the loops are interfaring inbetween one other when i use pagination
   to move the next page plz. what i did is created two list for displaying two 
   diffrnt category posts having 3 post at a time the next 3 post on the next page
   but when i click next page it move to next page correctly but with it the other
   loop also changes its post i don’t know wat to do to make it working plzzzzz 
   check here is the link for my [Home page ](http://e5media.info/gsk/) I would 
   love to get an anwser.If anyone can…
 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [13 years, 5 months ago](https://wordpress.org/support/topic/multiple-loops-additional-classes-pagination-help/#post-3137881)
 * [@raj](https://wordpress.org/support/users/raj/) You ought to create your own
   thread on the issue.

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

The topic ‘Multiple Loops Additional classes Pagination help’ is closed to new replies.

## Tags

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

 * 3 replies
 * 4 participants
 * Last reply from: [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * Last activity: [13 years, 5 months ago](https://wordpress.org/support/topic/multiple-loops-additional-classes-pagination-help/#post-3137881)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
