Support

Account

Home Forums Add-ons Repeater Field ACF Repeater show content in blocks

Solved

ACF Repeater show content in blocks

  • 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:

    • Item 1
    • Item 2
    • Item 3
    • Item 4
    • Item 5
    • Item 6
    • Item 7
    • Item 8
    • Item 9

    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!

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘ACF Repeater show content in blocks’ is closed to new replies.