高级自定义场循环图像

时间:2016-09-06 14:05:43

标签: wordpress advanced-custom-fields

我需要在高级自定义字段中显示循环。此代码仅返回第一个图像。

round(apply(array(unlist(m), c(3, 3, 3)), c(1,2), sd),2)
#    [,1] [,2] [,3]
#[1,] 1.00 1.15 1.53
#[2,] 1.15 2.08 3.21
#[3,] 2.31 4.93 2.89

1 个答案:

答案 0 :(得分:1)

在ACF转发器字段内,您必须使用get_sub_field(),而不是get_field()。所以你的代码应该是这样的:

<?php if( have_rows('colors') ): ?>

    <ul>

    <?php while( have_rows('colors') ): the_row(); ?>

    <?php   $image = wp_get_attachment_image_src(get_sub_field('colori'), 'full'); ?>
<img src="<?php echo $image[0]; ?>" alt="<?php echo get_the_title(get_sub_field('colors')) ?>" />

    <?php endwhile; ?>

    </ul>

<?php endif; ?>

它可能会再次返回false值,因为我不知道你如何命名你的ACF(转发器)子字段。

子字段'colori'必须是输出ID的ACF图像字段。不是数组或其他东西。

wp_get_attachment_image_src()返回一个数组。 [0] => url , [1] => width, [2] => height

阅读转发器字段here的文档。

相关问题