我正在使用ACF插件,我创建了一个灵活的内容来显示标题,内容和图库,但我无法获取图像。
我的代码是:
<div id="services-pages">
<?php
if( have_rows('serviços') ):
while ( have_rows('serviços') ) : the_row();
?>
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-6">
<div class="content">
<div class="title">
<hr>
<span><?php echo the_sub_field('title');?></span>
</div>
<div class="info">
<p><?php echo the_sub_field('content');?></p>
</div>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-6">
<div class="row images">
<?php
$images = the_sub_field('images');
var_dump($images);
?>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="slider-service-element">
<?php foreach( $images as $image ): ?>
<div>
<img src="<?php echo $image['url']; ?>" />
</div>
<?php endforeach; ?>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="slider-service-main">
<?php foreach( $images as $image ): ?>
<div>
<img src="<?php echo $image['url']; ?>" />
</div>
<?php endforeach; ?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
endwhile;
else :
?>
<div>
<span>no records</span>
</div>
<?php
endif;
?>
</div>
我已尝试使用get_field()
和the_sub_field()
获取图库。
我该如何解决?
谢谢。
答案 0 :(得分:1)
尝试这样的事情
$images = get_sub_field('images');
if( $images ):
foreach( $images as $image ):
?><img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" /><?php
endforeach;
endif;
在acf论坛上有关于它的帖子
https://support.advancedcustomfields.com/forums/topic/gallery-field-within-a-repeater-field/