Support

Account

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