Hi All
I really hope someone can help on this. I’ve a simple repeater but I need to return the values in blocks of 3. Like so:
I can get the repeater to divide into the 3 blocks but can’t return 3 rows per block
How can I do this?
Thanks
Hi,
I have an idea it’s not realy clean code, could use some improvement but it should work.
// check if the repeater field has rows of data
if( have_rows('repeater_field_name') ):
// loop through the rows of data
$i = 0;
while ( have_rows('repeater_field_name') ) : the_row();
$get_value = get_sub_field('sub_field_name');
$i++;
if($i == 1 || $i == 4 || $i == 7 ){
echo '<ul>'
}
// display a sub field value
echo '<li>' . $get_value . '</li>'
if($i == 3 || $i == 6 || $i == 9 ){
echo '</ul>'
}
endwhile;
else :
// no rows found
endif;
well that is not realy great if you want to change the number of content on each blocs but it could be perfecter for exemple if you add a custom field on you repeater (a true/false
for example that set the oppening <ul>
and another one that sets the closing </ul>
) you could look for those on the while loop and output an oppening or closing ul before or after an element
Thanks l.pirondini that really helped!