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