WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
How to mark every 3rd post
Style every four posts differently

Is it possible to repeat this loop after four posts? (post 5 = post 1 css, post 6 = post 2 css, etc..)

if (have_posts()):

   while (have_posts()) :



      if ($count == 1) : ?>

         <div>Styled post 1</div>

      <?php elseif ($count == 2) : ?>    

         <div>Styled post 2</div>

      <?php elseif ($count == 3) : ?>

         <div>Styled post 3</div>

      <?php elseif ($count == 4) : ?>  

         <div>Styled post 4</div>

      <?php else : ?>

      <?php endif;

endif; ?>
share|improve this question

marked as duplicate by Michael, Brian Fegter, kaiser, toscho Oct 3 '12 at 16:00

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 1 down vote accepted

Assuming that you're only using the counter to decide what style to use, the easiest way to achieve what you want would be to reset the $count variable once it gets to 4.

<?php elseif ($count == 4) : ?>  

    <div>Styled post 4</div>
    <?php $count = 0; ?>

<?php else : ?>
share|improve this answer
Works like a charm! Thanks! very appreciated :) – Phife Dawz Oct 2 '12 at 23:08

Not the answer you're looking for? Browse other questions tagged or ask your own question.