Tag Archives: class after every 3 posts

add custom class after every 3 posts inside loop list

<?php
            $args = array(
                'posts_type' => 'post'
            );
           
            $loop = new WP_Query($args);
            $i = 1;
            ?>
            <table style="float: left;width: 270px;">
            <?php
            while($loop->have_posts()){
                $loop->the_post();
                ?>
   
      <tr>
        <td><?php the_title(); ?></td>
        <?php //if($i % 3) //every 3rd post
            if($i == 3) //only 3rd post   
       
        { ?><td>bbbbbbbbbbbbb</td> <?php } ?>
      </tr>
  
    <?php
    $i++;
                }
           
             ?> </table>
Advertisements
%d bloggers like this: