WordPress 高级自定义字段,循环中继器

我有的

我在代码中的高级自定义字段和引导滑块中有一个中继器设置。

我想要达到的目标

我想在我的 WordPress 转发器中添加图像和文本,并让它填充我的滑块。这样每个新的中继器行都有自己的图像和文本。

我有图像工作,但不是文本,所以目前每张幻灯片都有自己的图像,但由于某种原因,我为每张幻灯片显示了所有文本。

下面是我的 ACF 中继器的布局

http://img.mukewang.com/61ee11ca00012a3013770451.jpg

波纹管是我当前的滑块

所以我有 3 张图片显示在正确的幻灯片上,但正如您所见,我的内容显示的不仅仅是与幻灯片相关的内容

http://img.mukewang.com/61ee11da0001aca207530734.jpg

摇曳的蔷薇
浏览 186回答 2
2回答

喵喵时光机

我已经自己解决了,我很接近,请看下面的答案<div class="carousel-inner">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <?php foreach ($sliderImages as $imgNumber => $image): ?>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="carousel-item<?php if ($imgNumber === 0) : ?> active<?php endif ?>">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <img src="<?= $image['image']['url'] ?>" alt="<?= $image['image']['alt'] ?>">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="carousel-text-block">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <h4 class="mb-1"> <?php echo $image['content_title']; ?></h4>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <p class="small m-0"> <?php echo $image['content']; ?></p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <?php endforeach ?>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>

幕布斯6054654

您将每个字段循环 2 次。您可以使用get_sub_field()以简化代码,请尝试以下操作:<div class="carousel-inner"><?php if (have_rows('section_8_slider')):&nbsp; &nbsp; while (have_rows('section_8_slider')): the_row();&nbsp; &nbsp; &nbsp; &nbsp; $image = get_sub_field('image');&nbsp; &nbsp; &nbsp; &nbsp; $content_title = get_sub_field('content_title');&nbsp; &nbsp; &nbsp; &nbsp; $content = get_sub_field('content');?>&nbsp; &nbsp; &nbsp; &nbsp; <div class="carousel-item">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <img src="<?= $image['url'] ?>" alt="<?= $image['alt'] ?>">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="carousel-text-block">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <h4 class="mb-1"> <?= $content_title;?></h4>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <p class="small m-0"> <?= $content;?></p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; <?php endwhile;endif; ?>希望能帮助到你
打开App,查看更多内容
随时随地看视频慕课网APP