Support

Account

Home Forums ACF PRO Display Gallery Images Excluding First? Reply To: Display Gallery Images Excluding First?

  • 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; ?>