Php 中继器中的ACF映像不工作
对于我正在创建的自定义WP主题,我使用的是ACF。我需要一个输出图像的中继器。我已将其设置为图像对象,并使用正确的代码。事实上,我在没有中继器的情况下试过,效果非常好。只有在中继器中它才会失败Php 中继器中的ACF映像不工作,php,wordpress,plugins,repeater,advanced-custom-fields,Php,Wordpress,Plugins,Repeater,Advanced Custom Fields,对于我正在创建的自定义WP主题,我使用的是ACF。我需要一个输出图像的中继器。我已将其设置为图像对象,并使用正确的代码。事实上,我在没有中继器的情况下试过,效果非常好。只有在中继器中它才会失败 <div class="row col-md-12"> <?php // check if the repeater field has rows of data
<div class="row col-md-12">
<?php
// check if the repeater field has rows of data
if( have_rows('pics') ):
// loop through the rows of data
while ( have_rows('pics') ) : the_row();
// display a sub field value
?><div class="col-md-4">
<?php
$image = get_field('img');
if( !empty($image) ): ?>
<img src="<?php echo $image; ?>" alt="<?php echo $image['alt']; ?>" />
<?php endif; ?>
</div> <?
endwhile;
else :
// no rows found
endif;
?>
</div>
“alt=”“/>
是什么导致图像数据不循环?您的代码看起来不错,但检查了我是如何做到的,我认为您应该使用
get\u sub\u field
而不是get\u field
你关于使用数组的['url']部分的评论也是相关的
$image = get_sub_field('img');
if( !empty($image) ): ?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php endif; ?>
$image=get_sub_字段('img');
如果(!empty($image)):?>
“alt=”“/>
您的代码看起来不错,但是检查了我是如何做到的,我认为您应该使用get\u sub\u field
而不是get\u field
您关于使用数组的['url']部分的评论也是相关的。这是为我工作
$image = get_sub_field('img');
if( !empty($image) ): ?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php endif; ?>
$image=get_sub_字段('img');
如果(!empty($image)):?>
“alt=”“/>
我认为这是你必须做的:
<?php
// check if the repeater field has rows of data
if( have_rows('img') ):
// loop through the rows of data
while ( have_rows('img') ) : the_row();
// display a sub field value
$image = get_sub_field('sub_img'); ?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php endwhile;
else :
// no rows found
endif;
?>
“alt=”“/>
这是假设您正在输出图像对象,而不是ACF设置中的url 我认为这是你必须做的:
<?php
// check if the repeater field has rows of data
if( have_rows('img') ):
// loop through the rows of data
while ( have_rows('img') ) : the_row();
// display a sub field value
$image = get_sub_field('sub_img'); ?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php endwhile;
else :
// no rows found
endif;
?>
“alt=”“/>
这是假设您输出的是图像对象,而不是ACF设置中的url。同样适用于img标记“echo$image['url'”;也不能解决问题。同样对于img标记“echo$image['url'”;“也不能解决问题。