views:

27

answers:

1

I'm working on a wordpress theme, and I have a rather unique structure that I need to output the results from the Loop into. The output can be simplified to the following:

<div class="row">
  <div class="entry-1">
    /* details from first iteration of The Loop */
  </div>
  <div class="entry-2">
    /* details from second iteration of The Loop */
  </div>
</div>
<div class="row">
  <div class="entry-3">
    /* details from third iteration of The Loop */
  </div>
  <div class="entry-4">
    /* details from fourth iteration of The Loop */
  </div>
</div>

So basically, I need the first two iterations of The Loop to output their details within a master DIV having the class name of "row". The next two iterations need to do the same, in a new DIV having the same aforementioned class name. This would continue on until have_posts() is false, accomodating the possibility of having a single remaining post, which would find itself alone within a master DIV having, again, the class name of "row".

I can't seem to think of the best way to accomplish this. Any direction would be greatly appreciated:

while ( have_posts() ) : the_post();
  /* My mind is blank */
endwhile;
+1  A: 
<?php

$i = 1; while ( have_posts() ) : the_post();

$even = ($i % 2);

if (!$even)
   echo '<div class="row">';
?>

<div class="entry-<?php echo $i; ?>">
    My Details
</div>

<?php

if ($even || $i == $wp_query->post_count)
   echo '</div>';

$i++; endwhile;
?>
TheDeadMedic