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