I am trying to make an grid of different size images using the ACF gallery field.
I have managed to do this before in a repeater field by counting rows, but have unable to adjust this to work with the gallery field.
My aim is to have a grid of 10 images using 2 different image sizes.
- Images 1, 2, 3, 6, 7, 8 would be one size
- Images 4, 5, 9, 10 would be a different size
My current markup is:
<?php
$images = get_field('home-image-grid');
$size = 'full';
if( $images ):
?>
<ul>
<?php foreach( $images as $image ): ?>
<li>
<?php echo wp_get_attachment_image( $image['ID'], $size ); ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
I have tried the markup I used previously with a repeater field, but this only outputs image 1.
<?php
$i = 1;
$images = get_field('home-image-grid');
$size = 'full';
if( $images ):
?>
<?php foreach( $images as $image ): ?>
<?php if ( $i == 1 ) { ?>
image 1
<?php } elseif ( $i == 2 ) { ?>
image 2
<?php } elseif ( $i == 3 ) { ?>
image 3
<?php } elseif ( $i == 4 ) { ?>
image 4
<?php } ?>
<?php endforeach; ?>
<?php endif; ?>
I presume this is because of the foreach statement. How can I get this to work?