Home › Forums › Add-ons › Repeater Field › Repeater Galleries
Hey everybody. I’m trying to display a gallery within a repeater field, with the ultimate goal of having multiple photo galleries on the same page that each attribute & link to their photographer. Unfortunately I can’t seem to get it to work!
Anybody know what I’m doing wrong? Here’s my snippet:
<?php if( have_rows('gallery') ): ?>
<?php while( have_rows('gallery') ): the_row();
$photog_name = get_sub_field('photographer');
$photog_link = get_sub_field('photographers_link');
$images = get_sub_field('photographers_gallery');
$size = 'thumbnail';
?>
<div class="the_gallery">
<p><a href="<?php echo $photog_link; ?>">Photos Provided by <?php echo $photog_name; ?></a></p>
<?php foreach( $images as $image ): ?>
<div class="gallery-item"><a href="<?php echo wp_get_attachment_url( $image['ID'], 'large' ); ?>" data-fancybox="gallery-<?php the_ID(); ?>"><?php echo wp_get_attachment_image( $image['ID'], $size ); ?></a></div>
<?php endforeach; ?>
</div>
<div class="clear"></div>
<?php endif; ?>
<?php endwhile; else : ?>
<p><?php esc_html_e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
This gives me an internal 500 error atm. I’m sure there’s just some simple php tweak I’m missing, but I can’t see it.
<?php if( have_rows('gallery-repeater') ): ?>
<!-- CHECK TO SEE IF IT HAS ROWS IN IT -->
<?php while ( have_rows('gallery-repeater') ) : the_row(); ?>
<!-- DISPLAY THE TEXT-FIELD THEN ASSIGN OUR GALLERY TO VARIABLE $images -->
<?php the_sub_field('gallery-name');
$images = get_sub_field('gallery-images');
if( $images ):?>
<?php foreach( $images as $image ): ?>
<a href="<?php echo $image['url']; ?>">
<img src="<?php echo $image['sizes']['thumbnail']; ?>" alt="<?php echo $image['alt']; ?>" />
</a>
<p><?php echo $image['caption']; ?></p>
<?php endforeach; ?>
<?php endif;
endwhile;
else :
// no rows found
endif; ?>
src: https://support.advancedcustomfields.com/forums/topic/gallery-field-inside-a-repeater-field/
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
Are you building WordPress sites with ACF and @BeaverBuilder, and wanted to use your ACF Blocks in both the block editor and Beaver Builder?
— Advanced Custom Fields (@wp_acf) May 10, 2023
The BB team recently added support for using ACF Blocks in Beaver Builder. Check it out 👇https://t.co/UalEIa5aQi
© 2023 Advanced Custom Fields.
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.