The cycle for the Bootstrap columns The essence of the cycle is as follows: if the post 3 or 6 is closed, but how to do that when the posts 5 or 4 should also be buried (that is, how to check if this is the last post also close)

<?php $args_montaj_system = array( 'teg_pages' => 'montazh-sistemi-opalennya', ); $posts_montaz = new WP_Query($args_montaj_system); $m = 1; if ($posts_montaz) { while($posts_montaz->have_posts()): $posts_montaz->the_post(); $thumb_id = get_post_thumbnail_id(); $thumb_url = wp_get_attachment_image_src($thumb_id,'thumbnail-size', true); if (($m == 1) || ($m == 4)) { echo "<div class='row'>"; } ?> <div class="col-md-6 col-lg-4"> <a href="<?php the_permalink(); ?>" class="wrap-syst-post"> <div class="image_syst-post" style="background-image: url('<?=$thumb_url[0];?>"> <!-- This image --> </div> <h4 class="title_syst-post"> <?php the_title(); ?> </h4> </a> </div> <?php if (($m == 3) || ($m == 6)) { echo "</div>"; } $m++; if ($m == 6) { $m = 1; } endwhile; } wp_reset_query(); // Restore global post data ?> 

    0