How do I add a class to every third post,
similar to how even/odd/alt is added to posts?
How do I add a class to every third post,
similar to how even/odd/alt is added to posts?
You can try it with a counter. Here is a very simple loop that gives every third post a class of "third-post";
<?php $counter =0; ?>
<?php while (have_posts()) : the_post(); ?><!-- begin of loop -->
<?php
++$counter;
if($counter == 3) {
$postclass = 'class="third-post"';
$counter = 0;
} else { $postclass = ''; }
?>
<div id="post-<?php the_ID(); ?>" <?php echo $postclass; ?>>
<?php the_content('Read the rest of this entry ยป'); ?>
</div>
<?php endwhile; ?><!-- end of loop -->Thanks a bunch!
This topic has been closed to new replies.