Created
February 11, 2014 10:15
-
-
Save schikulski/8932319 to your computer and use it in GitHub Desktop.
Wordpress: wrap 3 and 3 posts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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