0

I've made this code which seems to work (kind of), but I would like it to make rows every time there is 3 images in a row. I'm not sure i'm clear.

WHILE there is not 3 images in a row

ADD each of them in a col

WHEN there are 3 images in a row

PUT the next three ones in a row

Can you help me to get it work ?

      <div class="row">
          <?php $i = 0 ?>


          <?php while ($i < 3 && $the_query->have_posts() ) : $the_query->the_post(); ?>
            <div class="col-md-4">
            <?php the_post_thumbnail('actus');

            $i++?>

          </div>

          <?php $i = 0; endwhile; ?>
      </div>
Francis
  • 63
  • 1
  • 6
  • You can try using a [for loop](http://php.net/manual/en/control-structures.for.php) coupled with the [modulo operator](http://php.net/manual/en/language.operators.arithmetic.php). – Pyromonk Apr 26 '17 at 02:05
  • Hello, thank you for your answer. You mean instead of the while ? – Francis Apr 26 '17 at 02:07
  • Yes, while loops are normally used for very simple iterations. If there is a need to calculate something, that almost always means that you _should_ run a for loop. In this particular case, you just need an iterator for the loop, whether you retain while or substitute it with for is up to you – Pyromonk Apr 26 '17 at 03:13

0 Answers0