Reputation: 33
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?
Full PasteBin of the index file is here.
Upvotes: 0
Views: 1301
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