Support

Account

Home Forums Add-ons Repeater Field Repeater Galleries

Helping

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/

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Repeater Galleries’ is closed to new replies.