Title: WordPress Loop
Last modified: September 1, 2016

---

# WordPress Loop

 *  [aliakbari](https://wordpress.org/support/users/aliakbari/)
 * (@aliakbari)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/wordpress-loop-3/)
 * hi
    how to modify loop to split posts into groups of threes
 * Example
    -  <!–start loop–>
    -  <div class=”post-style-1″></div>
    -  <div class=”post-style-2″></div>
    -  <div class=”post-style-3″></div>
    -  <!–end loop–>
    -  <!–start loop–>
    -  <div class=”post-style-1″></div>
    -  <div class=”post-style-2″></div>
    -  <div class=”post-style-3″></div>
    -  <!–end loop–>

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/wordpress-loop-3/#post-7658092)
 * see for example [https://wordpress.org/support/topic/how-to-modify-loop-to-split-posts-into-groups-of-threes?replies=12#post-1604900](https://wordpress.org/support/topic/how-to-modify-loop-to-split-posts-into-groups-of-threes?replies=12#post-1604900)
 * what theme are you using?
    what is the original code of your loop?
 *  Thread Starter [aliakbari](https://wordpress.org/support/users/aliakbari/)
 * (@aliakbari)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/wordpress-loop-3/#post-7658143)
 * This topic could not help me
    [https://wordpress.org/support/topic/how-to-modify-loop-to-split-posts-into-groups-of-threes?replies=12#post-1604900](https://wordpress.org/support/topic/how-to-modify-loop-to-split-posts-into-groups-of-threes?replies=12#post-1604900)
 * please write loop for this html:
 * each post has different style in loop.
 * `
 * <ul>
    <li> <div class=post-style-one></div> <div class=post-style-tow></div> 
   <div class=post-style-three></div>
 * </li>
    <li> <div class=post-style-one></div> <div class=post-style-tow></div>
   <div class=post-style-three></div>
 * </li>
    </ul>
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/wordpress-loop-3/#post-7658259)
 * what theme are you using?
    what is the original code of your loop (index.php ?)?
 *  Thread Starter [aliakbari](https://wordpress.org/support/users/aliakbari/)
 * (@aliakbari)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/wordpress-loop-3/#post-7658265)
 * im use for slider.
 * my code:
 *     ```
       <ul>
   
       <!--start loop -->
       <li>
   
                   <!--posts % 3 == 0 -->
                   <div class="big-slide">
                       <a href="<?php the_permalink(); ?>">
                                alt="<?php the_title(); ?>" width="638" height="320" style="width: 638px; height: 320px;">
                       </a>
                   </div>
   
                   <!--posts % 3 == 1-->
                   <div class="small-slide">
                       <a href="<?php the_permalink(); ?>">
                                alt="<?php the_title(); ?>" width="312" height="157" style="width: 312px; height: 157px;">
                       </a>
                   </div>
   
                   <!--posts % 3 == 2-->
                   <div class="small-slide">
                       <a href="<?php the_permalink(); ?>">
                                alt="<?php the_title(); ?>" width="312" height="157" style="width: 312px; height: 157px;">
                       </a>
                   </div>
   
       </li>
   
       </ul>
       <!--end loop -->
       ```
   
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/wordpress-loop-3/#post-7658278)
 * this is the combination of your code with the code from [https://wordpress.org/support/topic/how-to-modify-loop-to-split-posts-into-groups-of-threes?replies=12#post-1604900](https://wordpress.org/support/topic/how-to-modify-loop-to-split-posts-into-groups-of-threes?replies=12#post-1604900),
   based on the default loop and query.
 * needs to be adapted if you are using a custom query to get the slides…
 *     ```
       <ul>
       <!--start loop -->
       <!-- open starting li before loop -->
       	<li>
       <?php while( have_posts() ) : the_post(); ?>
                   <div class="<?php echo( $wp_query->current_post % 3 == 0 ? 'big' : 'small' ); ?>-slide">
                       <a href="<?php the_permalink(); ?>">
                              <img src=""  alt="<?php the_title_attribute(); ?>" width="638" height="320" style="width: 638px; height: 320px;">
                       </a>
                   </div>
   
       		<?php $current_position = $wp_query->current_post + 1; // current_post starts at 0
       		if( $current_position < $wp_query->found_posts && $current_position % 3 == 0 ) : ?>
   
       		<!-- if position is equal to the divider and not the last result close the currently open div and start another -->
       		</li>
       		<?php echo "\n"; ?>
       		<li>
       		<?php endif; ?>
       	<?php endwhile; ?>
       	</li>
       	<!-- close whichever li was last open -->
       </ul>
       <!--end loop -->
       ```
   
 *  Thread Starter [aliakbari](https://wordpress.org/support/users/aliakbari/)
 * (@aliakbari)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/wordpress-loop-3/#post-7658279)
 * Thank You;
    How do I use every time the loop is just a series of custom post?
 * for examle:
 *     ```
       <li>
       custom post 1
       </li>
   
       <li>
       custom post 2
       </li>
   
       <li>
       custom post 3
       </li>
       ```
   
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/wordpress-loop-3/#post-7658280)
 * for custom posts, you will need to add a custom query before the loop, and adapt
   the code to the custom query.
 * [https://codex.wordpress.org/Class_Reference/WP_Query](https://codex.wordpress.org/Class_Reference/WP_Query)
   
   [https://codex.wordpress.org/Class_Reference/WP_Query#Type_Parameters](https://codex.wordpress.org/Class_Reference/WP_Query#Type_Parameters)

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

The topic ‘WordPress Loop’ is closed to new replies.

## Tags

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

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

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
