Wordpress - Add last class to every 4th post


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php if (have_posts()) : ?>
  2. <?php $count = 0; ?>
  3. <?php while (have_posts()) : the_post(); ?>
  4.  
  5.  
  6. <?php if ($count % 4 == 3) { ?>
  7. <div class="post last">
  8. <?php } else { ?>
  9. <div class="post">
  10. <?php } ?>
  11.  
  12. <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
  13. <div class="entry">
  14. <?php the_content(); ?>
  15.  
  16. </div>
  17. </div>
  18.  
  19. <?php $count++; ?>
  20. <?php endwhile; ?>
  21. <?php endif; ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.