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:
hope that help
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.