Reputation: 831
I want to add a clear div
(that is, <div class="clear></div>
) after every 3rd term, but I am having difficulties doing this within a foreach
block. I can, however, within a while loop.
Any help is greatly appreciated.
<?php
$terms = get_field('feature_choices');
// print_r($terms);
if( $terms ): ?>
<?php foreach( $terms as $term ): ?>
<div class="col-sm-3 margin_bottom">
<div class="row">
<div class="col-xs-2">
<img src="<?php bloginfo('template_directory'); ?>/assets/img/checkmark.png" alt="" />
</div>
<div class="col-xs-10">
<?php echo $term->name; ?>
</div>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
Upvotes: 0
Views: 1169
Reputation: 3648
add a counter
<?php $count = 1; foreach( $terms as $term ): ?>
<div class="col-sm-3 margin_bottom">
<div class="row">
<div class="col-xs-2">
<img src="<?php bloginfo('template_directory'); ?>/assets/img/checkmark.png" alt="" />
</div>
<div class="col-xs-10">
<?php echo $term->name; ?>
</div>
</div>
</div>
<?php if( $count % 3 == 0 ) echo "\n".'<div class="clear"></div>'; ?>
<?php $count++; endforeach; ?>
<?php endif; ?>
Upvotes: 1