Home › Forums › Add-ons › Gallery Field › Limit Image Gallery › Reply To: Limit Image Gallery
Hello I am trying to limit the gallery show only 2 images. But it doesn’t seem to work. Any idea what am I doing it wrong here?
Thanks
<?php
// if ACF is not active, abort.
if ( ! class_exists( 'acf' ) ) {
return;
}
$images = get_field( 'main_product_gallery' );
$size = 'medium'; // (thumbnail, medium, large, full or custom size)
if ( $images ) {
$counter = 1;
?>
<div class="product-gallery">
<?php
foreach( $images as $image ) {
?>
<div class="product-gallery__image-wrap ratio-1-1">
<?php echo wp_get_attachment_image( $image['ID'], $size );?>
</div>
<?php
$counter++;
if ($couner == 2) {
break;
}
}
?>
</div>
<?php
}
?>
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’re reaching out to our multilingual users to ask for help in translating ACF 6.1. Help make sure the latest features are available in your language here: https://t.co/TkEc2Exd6U
— Advanced Custom Fields (@wp_acf) May 22, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.