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(); ?>

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


Last Update on:March 5th, 2023 at 5:19 pm