Support

Account

Home Forums Add-ons Gallery Field How To display only one image in front end.

Solved

How To display only one image in front end.

  • How To display only one image in front end.

    eg: i have a photo gallery page and that have all the galleries i created. and this is a custom post. so my fields are title, content and gallery field. what i want to do is in the gallery page i want to show only title and one gallery image. if visitor click that thumbnail it goes to full gallery view page.. actually i can use featured image section to show that but i think it will be confusing my client. so i want to show only one image in that area.

    so can you help me with this… please..

  • Hi @Yashi

    The gallery field will return an array of images, correct?
    Knowing this, you can simply interact with the first element in the array like so:

    
    $images = get_field...
    $image_1 = $images[0];
    

    Good luck.

    Thanks
    E

  • This reply has been marked as private.
  • i found the solution and i resolved it thanks…. your example work for me

    <?php 
    
    $images = get_field('gallery_bucket'); 
    $image_1 = $images[0]; 
    
    ?>
    
    <img src="<?php echo $image_1['sizes']['gallery-thumb']; ?>" alt="<?php echo $image_1['alt']; ?>" />
Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘How To display only one image in front end.’ is closed to new replies.