How to Add a Gallery in an ACF Repeater – Oxygen Builder

Oxygen

December 9, 2021

Out of the box, the Oxygen Gallery element cannot show images from a gallery field in an Advanced Custom Fields repeater. You need to use a code block in your loop (or in your Oxygen Builder Repeater element if you’re using that).

You’ll also need a lightbox solution. Again, either a custom code solution or some 3rd party Oxygen addons let you define a custom gallery/lightbox source.

The custom code for use in your ACF Repeater to view your gallery images you can find below. Make sure to change ‘gallery’ to your gallery field name.

<?php 

$images = get_sub_field('gallery');

if( $images ): ?>
    <ul class="thumb-gallery">
        <?php foreach( $images as $image ): ?>
            <li class="thumb-gallery-li">
                     <img src="<?php echo $image['sizes']['thumbnail']; ?>" data-large="<?php echo $image['sizes']['large']; ?>" alt="<?php echo $image['alt']; ?>" />
                <p><?php echo $image['caption']; ?></p>
            </li>
        <?php endforeach; ?>
    </ul>
<?php endif; ?>

 

Join the Inside Link Community

Get access to all courses, weekly office hours, live build sessions, and an active community of WordPress professionals.

Learn More →