Title: WordPress multi loop and pagination
Last modified: August 31, 2016

---

# WordPress multi loop and pagination

 *  Resolved [underpk](https://wordpress.org/support/users/underpk/)
 * (@underpk)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/wordpress-multi-loop-and-pagination/)
 * Hi I’m currently working on this project
    [bsearch](http://bsearch.underpk.com/it%E3%83%BB%E3%83%9E%E3%83%BC%E3%82%B1%E3%83%86%E3%82%A3%E3%83%B3%E3%82%B0/)
 *     ```
       <?php
                   $args = array( 'posts_per_page' => 2, 'category' => 5 );
                   $myposts = get_posts( $args );
                   foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
   
                           // content of the first 2 post here //
   
                   <?php endforeach; wp_reset_postdata();?>
   
                   <?php
                   $args = array( 'posts_per_page' => 4, 'category' => 5,'offset' => 2 );
                   $myposts = get_posts( $args );
                   foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
   
                           // content of the last 4 post here //
   
                   <?php endforeach; wp_reset_postdata();?>
       ```
   
 * I searched and I knew that by this way the page pagination will not work. But
   I only know a few basic in wordpress and php coding.
 * Can anyone help me solve this problem please?
    Here is the design I made in [PSD](https://www.dropbox.com/s/5ri4ugjrayktedm/nextPage%20genre.jpg?dl=0)

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

 *  [Marvel Labs](https://wordpress.org/support/users/royalprince/)
 * (@royalprince)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/wordpress-multi-loop-and-pagination/#post-7205717)
 * Install a pagination plugin, and see if it fetches you desired results.
 * I get to see from your code that you want to display only four posts of category
   5 in single page and then paginate it.
 * If this is your front page, you could go to WordPress>Settings> Reading
 * and set blog posts to 4
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/wordpress-multi-loop-and-pagination/#post-7205722)
 * no need really to use two (foreach) loops for different styling or output of 
   the two first posts.
 * try to work with WP_Query() and a while loop, making use of conditional statements
   based on the buld-in loop counter `->current_post`
 * example:
 *     ```
       $args = array( 'posts_per_page' => 6, 'category' => 5, 'paged => get_query_var('paged') );
                   $myposts = new WP_Query( $args );
                   if( $myposts->have_posts() ) :
                   while( $myposts->have_posts() ) :
                   $myposts->the_post(); 
   
                   if( $myposts->current_post <= 1 ) : ?>
   
                           // content of the first 2 post here //
   
                   <?php else : ?>
   
                           // content of the last 4 post here //
   
                   endif; ?>
   
                   <?php endwhile; endif; wp_reset_postdata(); ?>
       ```
   
 * review
    [https://codex.wordpress.org/Pagination#Adding_the_.22paged.22_parameter_to_a_query](https://codex.wordpress.org/Pagination#Adding_the_.22paged.22_parameter_to_a_query)
 * the example might get more complicated if you want/need to wrap the two groups
   of posts each into different html containers.

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

The topic ‘WordPress multi loop and pagination’ is closed to new replies.

## Tags

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

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

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
