WordPress高级自定义字段,通过中继器循环 [英] WordPress advanced custom fields, loop though repeater
问题描述
我拥有的东西
我在高级自定义字段中有一个中继器设置,在我的代码中有一个引导程序滑块。
I have a repeater setup in Advanced custom fields and bootstrap slider in my code.
我要实现的目标
我想在WordPress中继器中添加图像和文本,让它填充我的滑块。
I would like to add a image and text in my WordPress repeater and have it populate my slider. so that each new repeater row has its own image and text.
我可以使用图像,但是不能使用文本,因此每张幻灯片现在都有自己的图像,但是出于某种原因,我要为每张幻灯片显示所有文本。
I have the image working, but not the text so at the moment every slide has its own image, but for some reason I have all the text displaying for each slide.
波纹管是我的ACF中继器的布局
波纹管是我当前的滑块
所以我在正确的幻灯片上显示了3张图片,但是正如您所见,我的内容不仅显示了与幻灯片相关的内容,而且还显示了所有图片
so I have 3 images that show on the correct slides but as you can see my content is showing all not just the content related for the slide
我的代码
<?php
$sliderImages = get_field('section_8_slider');
$count = 0;
$section = "section_8_";
$order = array();
?>
<div class="col-lg-8 mb-3">
<div class="carousel-inner">
<?php foreach ($sliderImages as $imgNumber => $image): ?>
<div class="carousel-item<?php if ($imgNumber === 0) : ?> active<?php endif ?>">
<img src="<?= $image['image']['url'] ?>" alt="<?= $image['image']['alt'] ?>">
<?php if (have_rows($section . 'slider')):
while (have_rows($section . 'slider')):
the_row(); ?>
<?php
foreach ($sliderImages as $i => $row)
if ($sliderImages ): ?>
<div class="carousel-text-block">
<h4 class="mb-1"> <?php echo $row['content_title']; ?></h4>
<p class="small m-0"> <?php echo $row['content']; ?></p>
</div>
<?php endif; ?>
<?php endwhile;
endif; ?>
</div>
<?php endforeach ?>
</div>
<a class="carousel-control-prev" href="#carousel_03" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only"></span>
</a>
<a class="carousel-control-next" href="#carousel_03" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only"></span>
</a>
</div>
推荐答案
我自己已经解决了这个问题,我很近,请参见下面的答案
I have managed to solve it myself, i was close, please see answer bellow
<div class="carousel-inner">
<?php foreach ($sliderImages as $imgNumber => $image): ?>
<div class="carousel-item<?php if ($imgNumber === 0) : ?> active<?php endif ?>">
<img src="<?= $image['image']['url'] ?>" alt="<?= $image['image']['alt'] ?>">
<div class="carousel-text-block">
<h4 class="mb-1"> <?php echo $image['content_title']; ?></h4>
<p class="small m-0"> <?php echo $image['content']; ?></p>
</div>
</div>
<?php endforeach ?>
</div>
这篇关于WordPress高级自定义字段,通过中继器循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!