[英]Display repeater field of ACF
i´m trying to display a repeater field made of images in my wordpress template but it just doesn´t work. 我正在尝试在wordpress模板中显示由图像组成的转发器字段,但是它不起作用。 I tried reading the doc of the plugin: http://www.advancedcustomfields.com/add-ons/repeater-field/ But still can´t make it work.
我尝试阅读该插件的文档: http : //www.advancedcustomfields.com/add-ons/repeater-field/但仍然无法使其正常工作。
Here it´s the markup: 这是标记:
<div id="slideshow">
<ul id="slides">
<li><img src="<?php the_repeater_field('home_slider'); ?>" alt="" /></li>
</ul>
</div>
The name of the repeater field is "home_slider" and the name of the field is "home_image". 转发器字段的名称为“ home_slider”,字段的名称为“ home_image”。 Please can someone help me out?
有人可以帮我吗?
This is what displays after load the page: 这是加载页面后显示的内容:
<img src alt>
The repeater-field stores everything in a array, so you need to retreive it then loop it out, try this: Repeater字段将所有内容存储在一个数组中,因此您需要检索它然后将其循环出,请尝试以下操作:
$slides = get_field('home_slider'); // Grabs the array
// Check if there is any data in the array before looping
if($slides) {
echo '<ul id="slideshow">';
foreach($slides as $s) {
echo '<li>';
echo '<img src="'.$s['home_image'].'" alt="" />';
echo '</li>';
}
echo '</ul>';
}
Now depending on what you set the image to return (image url, attachement ID or Image Object ) you will need to use different methods to get the path to the image. 现在,根据将图像设置为要返回的内容(图像url,附件ID或Image Object),您将需要使用不同的方法来获取图像的路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.