Support

Account

Home Forums Add-ons Gallery Field Skip first image of ACF Gallery in Repeater Field

Solving

Skip first image of ACF Gallery in Repeater Field

  • Hi,

    I need to skip the first image of a Gallery in a Repeater Field. I tried to modify the Code from here, but no luck: https://support.advancedcustomfields.com/forums/topic/display-gallery-images-excluding-first/

    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>
    ...

    Any idea?

    Thanks!

  • Hi, can anyone please help me on this? I need to skip the first image, because I need to display it outside of the foreach. Ty

  • Hey @nwde did you find the answer? I am looking for the exact same thing!

  • Hi,

    i used:

                        <?php $images = get_sub_field('portfolio_referenz_galerie_content');
                           if( $images ): ?>	
                           
    					        <?php 
    					          for($i=1; $i<count($images) && $i<100; $i++) {
    					            $image = $images[$i];
    					            ?>                       			
    				
    						<img src="<?php echo $image['url']; ?>" alt="" class="carousel-cell-img " />
    				
    				            <?php 
    				          }
    				        ?>
  • Hey @nwde you are a life saver, it’s working!

    Thanks a lot!

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

The topic ‘Skip first image of ACF Gallery in Repeater Field’ is closed to new replies.