Support

Account

Home Forums Add-ons Gallery Field Different layout in frontend Reply To: Different layout in frontend

  • use code like this that count images inside the gallery and depends on that count use a if else loop for the different outputs.

    <?php 
    $images = get_field('gallery'); 
    $total_images = count($images); //how many images are inside the gallery
    foreach( $images as $image ): 
    if ($total_images == 1){ //do what you wish i there is only one image
    echo '<img class="h400px" src="'. $image['sizes']['large'].'" alt="'.$image['alt'].'"  title="'.$image['title'].'"  />';
    } else { //do what you wish i there are multiple images
    echo '<img class="h200px" src="'. $image['sizes']['medium'].'" alt="'.$image['alt'].'"  title="'.$image['title'].'"  />';
    }
    endforeach;
    ?>

    depends on your needs choose at least one:

    • use the class and css to style the 2 imagesizes
    • add height param to the image
    • use own/additional media size with the sizes that you wish

    hope that help