$counter issue
-
Hi
The following code inserts a <div class=”row thirds”> div every 3 posts. But if there are 3 posts, an empty <div class=”row thirds”> is added. How do I prevent the empty div?
Thanks
<div class="row thirds"> <?php // Find connected pages $connected = new WP_Query( array( 'connected_type' => '2-col-module_to_pages', 'connected_items' => get_queried_object(), 'nopaging' => true, ) ); // Display connected pages if ($connected->have_posts() ) : while ($connected->have_posts()) : $connected->the_post(); ?> <h2><?php the_title();?></h2> <?php $counter++; // add row div every 3 posts if ($counter % 3 == 0) { echo '</div><div class="row thirds">'; } endwhile; wp_reset_postdata(); endif; ?> </div>
Viewing 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)
- The topic ‘$counter issue’ is closed to new replies.