Detect each 4 using modulus php


Staff member
I am trying to detect each 4th post to insert extra code in my layout in wordpress using modulus method but I just cant get it.

Here is a short example of mine:

<?php if (have_posts()) : ?>
<?php $count=0;?>   
<?php while (have_posts()) : the_post(); ?>

<div class="column">



            if ($count % 4 == 0){     
                echo '<div class="clear"></div>';

<?php endwhile; ?>
<?php endif; ?>

all that is inside the while loop. What am I doing wrong? Thank you.