Support

Account

Home Forums Add-ons Repeater Field Count in repeater field Reply To: Count in repeater field

  • hi john,

    thanks.

    function content_image($i)
        {
        ?>
            <?php 
                $count = count(get_sub_field('content_images'));  
                
                if( have_rows('content_images') ) :  
                      
                    if($count == 1) { ?>
                        <section class="grid gap-4 mt-6">
                    <?php }elseif($count == 2) { ?>
                        <section class="grid md:grid-cols-2 lg:grid-cols-2 xl:grid-cols-2 gap-4 mt-6">
                    <?php }elseif($count == 3) { ?>
                        <section class="grid md:grid-cols-3 lg:grid-cols-3 xl:grid-cols-3 gap-4 mt-6">
                    <?php } 
                    while( have_rows('content_images')) : the_row(); 
                        $image = get_sub_field('content_image'); ?>
                        <a data-fancybox="gallery" class="feature-zoom hover:shadow-2xl" href="<?= $image; ?>" title="&copy; <?php the_sub_field('content_image_copyright'); ?>" data-caption="&copy; <?php the_sub_field('content_image_copyright'); ?>">
                            <img src="<?= $image; ?>" title="&copy; <?php the_sub_field('content_image_copyright'); ?>" alt="">
                        </a>
                    <?php endwhile; ?>
                        </section>
                <?php endif; ?>
        <?php  
        }