Home › Forums › Add-ons › Repeater Field › ACF Repeater show content in blocks › Reply To: ACF Repeater show content in blocks
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
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.