How to Adding new Row class for every 3 post in WordPress loop

if you want to add row after 3 post hare is the solution. use below code wherever you want.

NOTE: I’m using bootstrap class for html structure and while loop for post repeat. you can use your own html structure and loop.

<div class="container">

<?php $i=1; 
	while ( have_posts() ) : the_post(); ?>

  <?php if($i==1) { ?>
  <div class="row">
  <?php } ?>
    
    <div class="col-sm-4">
      <h3><?php the_title(); ?></h3>
      <?php the_content(); ?>
    </div>

  <?php if($i==3) { ?>
  </div>
  <?php } $i++; 
    if($i==4){
        $i=1;
    }
    endwhile; ?>

</div>

Leave a Reply

Your email address will not be published.