最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Display repeater field of ACF - Stack Overflow

programmeradmin5浏览0评论

i´m trying to display a repeater field made of images in my wordpress template but it just doesn´t work. I tried reading the doc of the plugin: / But still can´t make it work.

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". Please can someone help me out?

This is what displays after load the page:

<img src alt>

i´m trying to display a repeater field made of images in my wordpress template but it just doesn´t work. I tried reading the doc of the plugin: http://www.advancedcustomfields./add-ons/repeater-field/ But still can´t make it work.

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". Please can someone help me out?

This is what displays after load the page:

<img src alt>
Share Improve this question asked Oct 16, 2012 at 14:44 user1617218user1617218
Add a ment  | 

1 Answer 1

Reset to default 6

The repeater-field stores everything in a array, so you need to retreive it then loop it out, try this:

$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.

发布评论

评论列表(0)

  1. 暂无评论