Support

Account

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

Solved

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.

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

    Cheers
    Luke

    • Elliot

    • July 12, 2013 at 4:45 pm

    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.

    Cheers
    Luke

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

You must be logged in to reply to this topic.

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.