Skip to content

Instantly share code, notes, and snippets.

@jmcclellan
Last active December 17, 2015 21:39
Show Gist options
  • Save jmcclellan/5675863 to your computer and use it in GitHub Desktop.
Save jmcclellan/5675863 to your computer and use it in GitHub Desktop.
Wordpress - Add CSS class to every fourth post
<?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