I have 12 image links in the db which I can call with get_field('opt3_img_N'), where N can be any number from 1 -12. (I'm using wordpress for anyone familiar).
What I'm having trouble with is coming up with an efficient way to output the images the way I want.
I need the links to be distributed into 3 divs equally. Ideally, I wanted image 1 to be in in div 1, image 2 in div 2, image 3 in div 3, image 4 in div 1, etc.
But, I cannot for the life of me, figure it out. I know this has probably been done in lots of ways, but I couldn't find anything on the net.
What I have right now is:
<div class="div-1">
<?php for( $i = 1; $i <= 4; $i++ ) {
$img = get_field( "opt3_img_$i" ) ?: get_template_directory_uri() . "/images/default.jpg";
$url = get_field( "opt3_url_$i" ) ?: "#"; ?>
<a href="<?php echo $url ?>"><img src="<?php echo $img ?>" /></a>
<?php endfor ?>
</div>
and so on with divs 2 and 3. Essentially it's sort of the brute force way of doing it. This does it for now, but I would like to know if there's a better way to do this.
PS. I'm not sure if this is a good question to ask here, so please vote to be moved if needed.
Thank you.