Support

Account

Home Forums General Issues Replace class name of last element in a repeater Reply To: Replace class name of last element in a repeater

  • Hi @avexdesigns

    I’m guessing the last class is so you can apply a specific margin?

    You can use a counter like so:

    
    <?php 
    
    $i = 0;
    $total = count( get_field('images', 'videoloc_14') );
    
    while(the_repeater_field('images', 'videoloc_14')): $i++; ?>
    	<?php $image = wp_get_attachment_image_src(get_sub_field('image'), 'full'); ?>
    	<a <?php if($i == $total): ?>class="last"<?php endif; ?> href="<?php the_sub_field('image_link'); ?>" target="_blank"><img class="class-name-to-replace" src="<?php echo $image[0]; ?>" /></a>
    	<?php endwhile; ?>
    <?php endif; ?>