Title: Split posts into unequal rows
Last modified: August 21, 2016

---

# Split posts into unequal rows

 *  Resolved [amcio](https://wordpress.org/support/users/amcio/)
 * (@amcio)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/split-posts-into-unequal-rows/)
 * Hello people!
    I have a little problem. I need to split desired amount of posts(
   10) into four rows. Odd rows should have two posts, and even rows should have
   three posts. I have no idea how to make The Loop to make things work. I have 
   no idea how to start. Can you help me out?
 * Any help appreciated very much!
 *     ```
       <div class="odd-row">
       two posts here
       </div>
       <div class="even-row">
       three posts here
       </div>
       <div class="odd-row">
       two posts here
       </div>
       <div class="even-row">
       three posts here
       </div>
       ```
   

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

 *  [shadez](https://wordpress.org/support/users/shadez/)
 * (@shadez)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/split-posts-into-unequal-rows/#post-4375134)
 * make use of a counter variable…
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/split-posts-into-unequal-rows/#post-4375176)
 * you can use the loop counter `$wp_query->current_post` with some conditional 
   statements;
    example::
 *     ```
       <?php
       while( have_posts() ) : the_post();
       	if( $wp_query->current_post%5 == 0 ) { echo "\n" . '<div class="odd-row">'; }
       	elseif( $wp_query->current_post%5 == 2 ) { echo "\n" . '<div class="even-row">'; }
   
       		//post content here//
   
       	if( $wp_query->current_post%5 == 1 || $wp_query->current_post%5 == 4 || $wp_query->current_post == $wp_query->post_count-1 ) { echo '</div>'; }
       endwhile;
       ?>
       ```
   
 *  Thread Starter [amcio](https://wordpress.org/support/users/amcio/)
 * (@amcio)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/split-posts-into-unequal-rows/#post-4375179)
 * Ok thanks. Now I have something like that:
 *     ```
       <?php if ( have_posts() ) : ?>
   
           <?php $counter = 0; ?>
   
             <?php while ( have_posts() ) : the_post(); ?>
   
               <?php $counter++; ?>
   
               <?php echo $counter. ' — '; the_title(); echo '<br>'; ?>
   
               <?php if ($counter == 2) { echo 'odd 2<Br><br>'; } ?>
               <?php if ($counter == 5) { echo 'even 3<Br><br>'; } ?>
               <?php if ($counter == 7) { echo 'odd 2<Br><br>'; } ?>
               <?php if ($counter == 10) { echo 'even 3<Br><br>'; } ?>
   
             <?php endwhile; ?>
   
           <?php endif; ?>
       ```
   
 * Can it be simplified more? ($counter == 2… $counter == 5…)
 * —
    Thanks [@alchymyth](https://wordpress.org/support/users/alchymyth/), I’ll 
   try your version! <3
 *  Thread Starter [amcio](https://wordpress.org/support/users/amcio/)
 * (@amcio)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/split-posts-into-unequal-rows/#post-4375186)
 * [@alchymyth](https://wordpress.org/support/users/alchymyth/) version works like
   a charm! Thank you boss

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

The topic ‘Split posts into unequal rows’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 3 participants
 * Last reply from: [amcio](https://wordpress.org/support/users/amcio/)
 * Last activity: [12 years, 5 months ago](https://wordpress.org/support/topic/split-posts-into-unequal-rows/#post-4375186)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
