Support

Account

Home Forums ACF PRO How to change basic Gallery code to assign a custom size for the first photo Reply To: How to change basic Gallery code to assign a custom size for the first photo

  • Add a counter to you loop and if it’s the first image then use a different size

    
    <?php 
      $images = get_field('gallery');
      if ($images) {
        ?>
          <div class="library">
            <?php 
              $first = true;
              foreach ($images as $image) {
                $url = $image['sizes']['large'];
                if ($first) {
                  // I made up a size here, you'll need to use a real size
                  $url = $image['sizes']['extralarge'];
                  $first = false;
                }
                ?>
                  <a href="<?php 
                    echo $url; ?>" class="item"><img src="<?php 
                    echo $url; ?>" alt="<?php echo 
                    $image['alt']; ?>" /></a>
                <?php 
              } // end foreach
            ?>
          </div>
        <?php 
      } // end if
    ?>