<?php query_posts(array('showposts' => 9, 'post_parent' => $post->ID, 'post_type' => 'page', 'order' => 'ASC')); ?>
<div>
<?php $i = 0; $attr = " class='clear_float'"; ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div<?php if(($i++)%3 == 0) {echo $attr;} ?>>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
</div>
<?php endif; ?>
</div>
<?php wp_reset_query(); ?>
I added 2 lines.
<?php $i = 0; $attr = " class='clear_float'"; ?>
and
<div<?php if(($i++)%3 == 0) {echo $attr;} ?>> <!-- clear class on each 4th item -->
===== UPDATED =====
To add a 3rd class class, I would suggest adding a class to all elements, for simplicity and even more control
To do this, before the loop:
$i = 0;
Inside divin a loop:
<div class="item-<?php echo (($i++) % 3) + 1 ?>">
So, for each row, the first element has a class = item-1, the third element has a class =item-3
source
share