Home › Forums › Add-ons › Repeater Field › Is there a way to separate repeater rows by groups of five? › Reply To: Is there a way to separate repeater rows by groups of five?
<?php
$count = 0;
$your_repeater = get_field('your_repeater');
if($your_repeater){
echo '<div class="headerrow">header</div>';
while( have_rows('your_repeater') ): the_row();
$count++;
$my_field = get_sub_field('my_field');
echo '<div class="row">'.$my_field.'</div>';
if ($count % 5 == 0) {
echo '<div class="specialrow">subheader</div>';
}
endwhile;
}
?>
with that code every 5 row a additional row is added (always the same)
if you need each 5 row totally different code, replace
if ($count % 5 == 0)
with if ($count == 5)
and add a if-loop for each additional 5 rows
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.