I want to multiple of 2 close div and open a new div in wp loop using shortcode post loop.
if($i % 2 == 0) {echo '</li><li>';}
$i++;
How Can do it?
General loop:
<?php
$i = 1;
//added before to ensure it gets opened
echo '<li>';
if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post();
// post stuff...
?>
<div class="frCol"><a href="#"><?php the_post_thumbnail('thumbnail', array('class' => 'imgthumb')); ?></a>
<div class="item-info">
<h2><?php the_title(); ?></h2>
</div>
</div>
<?php
// if multiple of 3 close div and open a new div
if($i % 2 == 0) {echo '</li><li>';}
$i++; endwhile; endif;
//make sure open div is closed
echo '</li>';
?>
This is the shortcode:
function testimonial_thumb_shortcode($atts){
extract(shortcode_atts(array(
'category' => ''
), $atts));
$q = new WP_Query(array(
'posts_per_page' => -1,
'post_type' => 'testimonials',
'testimonial_cat' => $category
));
$list = ' <ul>';
while($q->have_posts()):
$q->the_post();
$idd = get_the_ID();
$author_photo = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'thumbnail');
$list .= '/*Main loop*/';
endwhile;
$list.= '</ul>';
wp_reset_query();
return $list;
}
add_shortcode('tthumb', 'testimonial_thumb_shortcode');