Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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..)

<?php
if (have_posts()):

   while (have_posts()) :

      the_post();

      $count++;

      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;

   endwhile;
endif; ?>
share|improve this question
add comment

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.

1 Answer

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
add comment

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