Skip to content

Instantly share code, notes, and snippets.

@schikulski
Created February 11, 2014 10:15
Show Gist options
  • Save schikulski/8932319 to your computer and use it in GitHub Desktop.
Save schikulski/8932319 to your computer and use it in GitHub Desktop.
Wordpress: wrap 3 and 3 posts
<?php
if(have_posts()) : for($count=0;have_posts();$count++) : the_post();
$open = !($count%3) ? '<div class="threeacross">' : ''; //Create open wrapper if count is divisible by 3
$close = !($count%3) && $count ? '</div>' : ''; //Close the previous wrapper if count is divisible by 3 and greater than 0
echo $close.$open;
?>
<?php // do stuff ?>
<?php endfor; else : ?>
<h1>Not found.</h1>
<?php endif; ?>
<?php echo $count ? '</div>' : ''; //Close the last wrapper if post count is greater than 0 ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment