Last active
December 17, 2015 21:39
-
-
Save jmcclellan/5675863 to your computer and use it in GitHub Desktop.
Wordpress - Add CSS class to every fourth post
This file contains hidden or 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()) : ?> | |
<?php | |
// declare counter variable and assign it a value of 0 | |
$count = 0; | |
?> | |
<?php while (have_posts()) : the_post(); ?> | |
<?php if ($count % 4 == 3) { echo '<div class="post className">'; } else { echo '<div class="post>'; } ?> | |
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> | |
<div class="entry"> | |
<?php the_content(); ?> | |
</div> | |
</div><!-- .post --> | |
<?php | |
// increment counter every time the loop is run | |
$count++; | |
?> | |
<?php endwhile; ?> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment