Row 3 post, new row 2 posts, repeat?

Hi,

I would like to ge this markup when looping out my posts:

<div class="row">
<div class"post"></div><div class"post"></div><div class"post"></div>
</div>
<div class="row">
<div class"post"></div><div class"post"></div>
</div>
<div class="row">
<div class"post"></div><div class"post"></div><div class"post"></div>
</div>
<div class="row">
<div class"post"></div><div class"post"></div>
</div>

etc...

Basically I want a row with three posts, then one with two, then with three, and so on. Is this possible?

This is my current loop:

<?php
	$args = array(
		'post_type' => 'members'
	); 
	$the_query = new WP_Query( $args );
?>
<?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
	<div class="post"></div>
<?php endwhile; endif; wp_reset_query(); ?>

While it won’t win any awards for sexiness, this should work for you, if I’m understanding your needs correctly:

<?php $args = array('post_type' => 'members'); $the_query = new WP_Query( $args ); $class='triple'; $count = 0; if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); if($class == 'triple' AND $count == 3){ $class = 'double'; $count = 0; }elseif($class == 'double' AND $count == 2){ $class = 'triple'; $count = 0; } echo'<div class="'.$class.'"></div>'; $count = ++$count; endwhile; endif; wp_reset_query(); ?>

Happy bunny day!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.