Support

Account

Home Forums ACF PRO Display Gallery Images Excluding First?

Solved

Display Gallery Images Excluding First?

  • Is it possible to display a list of gallery images excluding the first one of the group?

  • This code is taken from https://www.advancedcustomfields.com/resources/gallery/ with a little addition to skip the first image. I added a counter and check it to see if it’s the first one.

    
    <?php 
    
    $images = get_field('gallery');
    
    if( count($images) > 1 ): 
    $count = 0;
    ?>
        <ul>
            <?php foreach( $images as $image ): 
    if ($count == 0) {
      // skip the first one
      continue;
    }
    $count++;
    
    ?>
                <li>
                    <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>
                </li>
            <?php endforeach; ?>
        </ul>
    <?php endif; ?>
    
  • Brilliant thank you John.

  • Hello,

    I can not get this working within a repeater field. Any idea, thanks! This is my code:

    
    ...
    					<?php elseif(get_row_layout() == "portfolio_referenz_galerie"): ?>			
    
    				<div class="carousel-container">
                    	<div id="carousel-<?php the_sub_field('galerie_id'); ?>" class="carousel" data-flickity='{ "imagesLoaded": true, "setGallerySize": false, "lazyLoad": true }'>
                      
    						<?php 
    				        $placeholder = get_sub_field('portfolio_referenz_galerie_content'); 
    				        $placeholder_1 = $placeholder[0]; 
    				        ?>                      
    
                      		<img src="<?php echo $placeholder_1['url']; ?>" alt="" id="carousel-cell-img-<?php the_sub_field('galerie_id'); ?>" class="carousel-cell-img placeholder" />
                      
    							<?php 
    							
    							$images = get_sub_field('portfolio_referenz_galerie_content');
    							
    							if( count($images) > 1 ): 
    							$count = 0;
    							?>
    							
    							
    							        <?php foreach( $images as $image ): 
    							if ($count == 0) {
    							  // skip the first one
    							  continue;
    							}
    							$count++;
    							
    							?>			
    				
    						<img src="placeholder-2500-1406.png" data-flickity-lazyload="<?php echo $image['url']; ?>" alt="" id="carousel-cell-img-<?php the_sub_field('galerie_id'); ?>" class="carousel-cell-img" />
    						
                                <?php endforeach; ?>
    					
                        <?php endif; ?>
    
                  	  </div>
    ...
  • I tried the exact above code (in and out a repeater) but it doesn’t seem to working anymore. Do you guys happen to know why?

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

The topic ‘Display Gallery Images Excluding First?’ is closed to new replies.