woodini
woodini

Reputation: 33

Return first image in gallery array of Pods Framework in WordPress

I have a mutidimensional array called 'gallery' in Pods that only contains photographs. I only want to return the first image of the array in my WordPress page, however all of the pics in the array are being displayed. Here's the code I'm currently using:

<?php foreach($vehiclepods->field('gallery', true) as $picture) { ?> <img src="<?php echo $picture['guid'];?>" alt="image" /></a> <?php } ?>

What am I doing wrong and how can I just get the first image in the array to show up?

screenshot of output

Full PasteBin of the index file is here.

Upvotes: 0

Views: 1301

Answers (1)

Orlando P.
Orlando P.

Reputation: 631

Well your output for images is wrapped in a foreach. So your going to get every image if you only want the first one use

$gallery = $vehiclepods->field('gallery', true);

<img src="<?php echo $gallery[0]['guid'];?>" alt="image" />

This way gallery is an array and you are getting the first image src in the array. with [0][guid]

Upvotes: 0

Related Questions