I’m using bootstrap 3 and I would like to group 3 post categories per row to get a proper grid system but I don’t know how to make a counter. Can anybody help me with this?
Here is my code:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID
);
$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
echo '<div class="col-md-4">';
echo '<a href="';
echo the_permalink();
echo '">';
echo wp_get_attachment_image( $attachment->ID, 'full' );
echo '</a>';
echo '<h3 class="category-title"><a href="';
echo the_permalink();
echo '">';
echo the_title();
echo '</a></h3>';
echo '</div>';
}
}
endwhile; endif; ?>
I would like to have something like this
<div class="row">
<div class="col-md-4">Content</div>
<div class="col-md-4">Content</div>
<div class="col-md-4">Content</div>
</div>
<div class="row">
<div class="col-md-4">Content</div>
<div class="col-md-4">Content</div>
<div class="col-md-4">Content</div>
</div>
Thank you very much for your help.
Use PHP’s MOD to test for a remainder: