Prevent empty div after post loop


The following code inserts a div with row class every 2 posts. It works fine except if there are an even number of posts/multiples of 2, it adds an extra empty div to the end of the loop. Can anyone help fix this for me?

<div class="row">


$connected = new WP_Query( array(

'connected_type' => '2-col-module_to_pages',

'connected_items' => get_queried_object(),

'nopaging' => true,

) );

if ($connected->have_posts() ) : while ($connected->have_posts()) : $connected->the_post(); ?>

<div class="tile">

<div class="wrapper">

<div class="content">

<h2><?php the_title();?></h2>




<?php $counter++;

if ($counter % 2 == 0 ) {

echo '</div><div class="row">';


endwhile; wp_reset_postdata(); endif; ?>


Beceriler: PHP, WordPress

Daha fazlasını gör: prevent, div, php post array, div fix, post content wordpress php, empty, class wrapper, wrapper class, wordpress wrapper, tile code, loop row php, div div php, counter post, loop post number php, wordpress counter, array div, wordpress loop, can post adds, div array php, add flash object java script wordpress post

İşveren Hakkında:
( 13 değerlendirme ) London, United Kingdom

Proje NO: #6502180



I m expert in this. I have +5years experience. Following are my recently completed project: Wordpress [login to view URL] [login to view URL] [login to view URL] [login to view URL] Daha Fazla

1 gün içinde %selectedBids___i_sum_sub_4%%project_currencyDetails_sign_sub_5% GBP
(135 Değerlendirme)

We believe good design is like good manners, you just simply have it and you do not need to prove it. You might not find us on Award lists and we do not aim to get any award. Our award = superb result = happy client. W Daha Fazla

1 gün içinde %selectedBids___i_sum_sub_4%%project_currencyDetails_sign_sub_5% GBP
(5 Değerlendirme)

Bu iş için 4 freelancer ortalamada £15 teklif veriyor


Dear Sir, I have read your job description. I can do this job. I have 5 years experience about wordpress. You can check my portfolio for my previous work. I am available form now and weekly 40 hours. Waiting for your r Daha Fazla

1 gün içinde %bids___i_sum_sub_32%%project_currencyDetails_sign_sub_33% GBP
(47 Değerlendirme)

Hello Sir, I have experience working with PHP and wordpress. For instance, you can have a look at [login to view URL], which is a project in which I was part of the developer team. I can deliver what you Daha Fazla

1 gün içinde %bids___i_sum_sub_32%%project_currencyDetails_sign_sub_33% GBP
(0 Değerlendirme)