Home Forums Front-end Issues Repeater Sub Field: Display last item if empty


Repeater Sub Field: Display last item if empty

  • Hello!

    I have a question regarding repeater fields.

    So I have a repeater with 2 subfields — Featured Image and Additional Image.

    I have 2 rows of items. The 1st row has both the featured image and additional image — but the 2nd row only has the additional image.

    Screenshot for reference:

    I can get the second additional image to display — but since I left the featured image empty in the 2nd row, I’m getting a blank image.

    Currently my php is set up like this:

    <?php if(have_rows(‘large_image_layout’)) { ?>
    <?php while(have_rows(‘large_image_layout’)) {
    $featured_image = get_sub_field(‘featured_image’);
    <?php } ?>
    <?php } ?>
    <div class=”featured-image” style=”background-image:url(<?php echo $featured_image; ?>);”></div>

    How would I go about only getting the item from the first row? Or check if the row is empty, return the last item or first row item?

    Thanks so much!

Viewing 1 post (of 1 total)

The topic ‘Repeater Sub Field: Display last item if empty’ is closed to new replies.