Home › Forums › Add-ons › Repeater Field › Count in repeater field
Hi,
i have an repeater field for images and try to set classes for one, two or three images. will set the section layout if only 1 images to full width, 2 images (to grid-cols-2) and 3 images (to grid-cols-3)
<section class="grid md:grid-cols-3 lg:grid-cols-3 xl:grid-cols-3 gap-4 mt-6">
<?php
if( have_rows('content_images') ) : 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="© <?php the_sub_field('content_image_copyright'); ?>" data-caption="© <?php the_sub_field('content_image_copyright'); ?>">
<img src="<?= $image; ?>" title="© <?php the_sub_field('content_image_copyright'); ?>" alt="">
</a>
<?php endwhile; endif; ?>
</section>
hope someone can help me
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="© <?php the_sub_field('content_image_copyright'); ?>" data-caption="© <?php the_sub_field('content_image_copyright'); ?>">
<img src="<?= $image; ?>" title="© <?php the_sub_field('content_image_copyright'); ?>" alt="">
</a>
<?php endwhile; ?>
</section>
<?php endif; ?>
<?php
}
You must be logged in to reply to this topic.
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.