Home Forums Add-ons Gallery Field Gallery Code Not Working


Gallery Code Not Working

  • <?php 
    $images = get_field('gallery');
    if( $images ): ?>
            <?php foreach( $images as $image ): ?>
                    <a href="<?php echo $image['url']; ?>">
                         <img src="<?php echo $image['sizes']['thumbnail']; ?>" alt="<?php echo $image['alt']; ?>" />
                    <?php echo $image['caption']; ?>
            <?php endforeach; ?>
    <?php endif; ?>

    I am using the above code in X theme but nothing shows up in my posts. Any ideas as to why?

    This code works:

    $image_ids = get_field('gallery', false, false);
    $shortcode = '[gallery ids="' . implode(',', $image_ids) . '"]';
    echo do_shortcode( $shortcode );

    but the images are unformatted and not linked to large versions of the images.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.