Support

Account

Home Forums Add-ons Repeater Field Assign classes to repeater divs in iterations of 3 Reply To: Assign classes to repeater divs in iterations of 3

  • Here is the solution in case anyone is wondering:

    <?php
    
    if( have_rows('slide') ):
        $i = 1;
        while ( have_rows('slide') ) :
            the_row();
            // Check if we've reached our limit, and if so... start again! 
            if ( $i > 3 )
            {
                $i = 1;
            }
        ?>
    
            <div class="slide num-<?php echo $i; ?>">
                <p><?php the_sub_field('text1'); ?></p>
                <p><?php the_sub_field('text2'); ?></p>
            </div>
    
        <?php
            $i++;
        endwhile;
    endif;
    
    ?>