Question

I’m trying to show only one image from my gallery field as a thumbnail and when the viewer clicks it a fancybox slideshow pops up.

This is what I have so far:

<?php 
    $images = get_field('gallery'); 
    $image_1 = $images[0]; 
    ?>    

    <img src="<?php echo $image_1; ?>" />    

But the HTML shows this…

<img src="Array">

Please advise.

Was it helpful?

Solution 2

I changed the code to this;

        <?php 
        $images = get_field('gallery'); 
        $image_1 = $images[0]; 
        ?>    

        <img src="<?php echo $image_1[url]; ?>" />  

OTHER TIPS

You said you changed the code, but did it help? If it did you should mark your answer as "Accepted", so the question can be closed.

If not, then try this, assuming you're using the field as an Image Object (chosen when you create the Image Field):

<?php 
$images = get_field('gallery'); // get gallery
$image  = $images[0]; // get first image in the gallery [1] for second, [2] for third, and so on.

if( $image ) : // only show the image if it exists ?> 
    <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php endif; ?>

Remember the ' or " around the ['value']

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top