How can I add a <div class="break"></div>
after 4 rows in a repeater field?
<?php if(get_field('vessel-more-information')): ?>
<div class="vesselInfo">
<div class="row">
<?php while(has_sub_field('vessel-more-information')): ?> <div class="col-md-3"><strong><?php the_sub_field('title'); ?></strong> <br><?php the_sub_field('content'); ?></div>
<?php endwhile; ?>
</div>
<?php endif; ?>
Hi there, I’ve run into similar issues. This article helped me out a lot:
http://stackoverflow.com/questions/936242/php-how-do-you-determine-every-nth-iteration-of-a-loop
You’ll need to start a counter just above your while loop:
$counter = 0;
You should be able to drop an if statement into your while loop:
if ($counter % 4 == 0) {
// code here
}
Then just before your closing endwhile; you’ll need to advance the counter:
$counter ++;
The if statement will evaluate to true every 4 iterations of the loop.
Thanks again @smspaul. 🙂 Did that help you out @magnusnesse?