Home Forums Add-ons Gallery Field Is this the correct way to display gallery images?


Is this the correct way to display gallery images?

  • I searched high and low for a simple way to just display the images in a gallery on a page/post, without the use of any gallery functionality.

    I ended up hacking the example code and .keep what (I think) I need to get the job done. It works so I might have it right? It would be great to have a simple sample like this in the documentation, that would have saved me a lot of time and might be a good proof of concept to test the output is working in a visually correct way on a site.

    $images = get_field('gallery_images');
    if( $images ): ?>
    			<?php foreach( $images as $image ): ?>
    					<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
    			<?php endforeach; ?>
    	<?php endif; ?>


  • Hi @lukehallam

    Your code looks fine. There is no bloated of unnecessary code so this gets the stamp of approval from me.

    Did you find the documentation example a but too overwhelming?

  • That’s Elliot,

    Yeah, the image gallery code, although very clear, was something I had to strip out to get what I needed, which I think is the simplest use of the plugin/add-on. Not being a coder, this was a challenge and I was a little surprised there wasn’t a simpler example available.

    I can see that the image gallery implementation is probably the most in-demand function of this add-on so I understand why it has been provided as an example.


Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Is this the correct way to display gallery images?’ is closed to new replies.