Skip to content

Instantly share code, notes, and snippets.

@ebinnion
Created January 20, 2013 21:31
Show Gist options
  • Save ebinnion/4581906 to your computer and use it in GitHub Desktop.
Save ebinnion/4581906 to your computer and use it in GitHub Desktop.
WordPress Loop Group of Three
<?php if (have_posts()) :
$i=0; // counter
while(have_posts()) : the_post();
if($i%3==0) { // if counter is multiple of 3, put an opening div ?>
<!-- <?php echo ($i+1).'-'; echo ($i+3); ?> -->
<div class="cf">
<?php } ?>
<div class="col3 toolbox">
<div class="head">
<h5 style="text-align:center;"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h5>
<div class="aligncenter"><a href="<?php the_permalink() ?>"><?php if(has_post_thumbnail()) { the_post_thumbnail('featured'); } ?></a></div>
</div>
<p><?php echo get_post_meta( get_the_ID(), 'ta_post_review_summary', true) ?></p>
</div>
<?php $i++;
if($i%3==0) { // if counter is multiple of 3, put an closing div ?>
</div>
<div class="line-separator"></div>
<?php } ?>
<?php endwhile; ?>
<?php
if($i%3!=0) { // put closing div here if loop is not exactly a multiple of 3 ?>
</div>
<?php } ?>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment