Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    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 -->
    Thread Starter UlukaiThemeDesign

    (@ulukaithemedesign)

    Thanks a bunch!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add class to every third post?’ is closed to new replies.