简体   繁体   English

在WordPress的Pods Framework的图库数组中返回第一个图像

[英]Return first image in gallery array of Pods Framework in WordPress

I have a mutidimensional array called 'gallery' in Pods that only contains photographs. 我在Pod中有一个名为“ gallery”的多维数组,其中仅包含照片。 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. 我只想在我的WordPress页面中返回该数组的第一张图片,但是正在显示该数组中的所有图片。 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. 索引文件的完整PasteBin在这里。

Well your output for images is wrapped in a foreach. 好吧,您的图像输出包装在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. 这样,图库是一个数组,您将获得数组中的第一个图像src。 with [0][guid] [0][guid]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM