Home Forums Add-ons Repeater Field Add a class to last field within a repeater


Add a class to last field within a repeater

  • Hi All,

    Just wondering if anybody could give me some advice/help please.

    I need to add a class to an image tag, if it is the last field within the repeater. I’ve managed to add a class to the first image within the repeater field, but struggling to do the last. This is my current code:

    <?php if( have_rows('accreditations', 'option') ): $count = 0; ?>
    <?php while ( have_rows('accreditations', 'option') ) : the_row(); ?>
    <div class="col-lg-2 col-md-2 col-sm-6">
    <?php $logo = get_sub_field('logo'); if( !empty($logo) ): ?>
    <img <?php if (!$count) { ?> class="first-logo"<?php } ?> class="img-fluid " src="<?php echo $logo['url']; ?>" alt="<?php echo $logo['alt']; ?>" />
    <?php endif; ?>
    </div><!--End Columns-->
    else :
    • rdm

    • February 20, 2019 at 10:18 am

    Have you considered using :last-child?

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

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.