I am trying to make Wordpress loop with php modulus. The scenario is wrapping every 3 posts in a div
. My script below is working perfectly, except I found an unused empty div
at the last (from inspect element).
$loop_args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 6
);
$loop = new WP_Query( $loop_args );
<?php if( $loop->have_posts() ): ?>
<div class="row">
<?php $count = 0; ?>
<div class="col-md-6">
<?php while( $loop->have_posts() ) : $loop->the_post(); $count++; ?>
<?php if( $count % 3 == 0 ): ?>
<article class="post-content"><?php the_title();?></article>
</div> <!-- .col md 6 -->
<div class="col-md-6">
<?php else: ?>
<article class="post-content"><?php the_title();?></article>
<?php endif; // end modulus ?>
<?php endwhile; // end while loop ?>
</div> <!-- .col md 6 -->
</div> <!-- .row -->
<?php endif; wp_reset_postdata(); ?>
Please take a look at the last highlighted div
in my attachement:
How can I remove that unused empty div
?
Thanks in advance.