我正在使用WordPress和高级自定义字段,我想要显示3-6图像,这取决于在选择字段帖子类型上选择的字段。
我有它,所以值/变量绑定到图像名称中,所以它将根据您的选择显示所选的图像。
例如"red : Red“
<img src="example.com/images/image-<?php the_field(color) ?>.jpg" alt="<?php the_field(color) ?>">现在的noob问题是,当选择多个字段时,它将返回一个数组(即红、绿、黑)。而且我不能让函数输出为数组,因为它不会与图像名称匹配。
有人知道如何将一个数组用于多个图像输出吗?
发布于 2013-04-22 06:05:13
foreach ($image_list as $image) {
printf('<img src="example.com/images/image-%s.jpg" alt="%s" />', $image['color'], $image['color']);
}如果您没有关联的数组,而只有一个简单的数组,您可能会这样做:
foreach ($gem_colors as $color) {
printf('<img src="example.com/images/image-%s.jpg" alt="%s" />', $color, $color);
}发布于 2013-04-22 05:52:46
类似于:
<?php foreach($imageArray as $row): ?>
<img src="example.com/images/image-<?php echo $row['color']; ?>.jpg" alt="<?php echo $row['color']; ?>">
<?php endforeach; ?>https://stackoverflow.com/questions/16136566
复制相似问题