如何输出组内中继器的图像?

我正在尝试从高级自定义字段中组内的转发器输出图像,但无法获取图像 URL。该组称为“主页”,转发器称为“幻灯片”,字段为“background_image”。


请看下面的代码。


    $rows = get_field('slideshow');


    if($rows) {

        $image = get_field('background_image');

        $size = 'full';


        foreach($rows as $row) {

?>

            <li class="swiper-slide">

                <div class="bg parallax2" data-speed='.5' style='background-image: url("<?php echo $image['url']; ?>")'></div>

            </li>

<?php

        }

    }

?>

背景图片 URL 为空。


繁星淼淼
浏览 167回答 2
2回答

交互式爱情

转发器内的字段将称为子字段 ( get_sub_field),因此您的代码应该是&nbsp; &nbsp; &nbsp; $rows = get_sub_field('slideshow');&nbsp; &nbsp; if($rows) {&nbsp; &nbsp; &nbsp; &nbsp; $image = get_sub_field('background_image');&nbsp; &nbsp; &nbsp; &nbsp; $size = 'full';&nbsp; &nbsp; &nbsp; &nbsp; foreach($rows as $row) {?>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <li class="swiper-slide">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="bg parallax2" data-speed='.5' style='background-image: url("<?php echo $image['url']; ?>")'></div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </li><?php&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }?>

慕工程0101907

这应该有效:<?php$homepageFields = get_field('homepage');$slideshow = $homepageFields['slideshow'];if ($slideshow) {&nbsp; &nbsp; $size = 'full';&nbsp; &nbsp; foreach ($slideshow as $row) {&nbsp; &nbsp; &nbsp; &nbsp; $image = $row['background_image'];&nbsp; &nbsp; &nbsp; &nbsp; ?>&nbsp; &nbsp; &nbsp; &nbsp; <li class="swiper-slide">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="bg parallax2" data-speed='.5' style='background-image: url("<?php echo $image['sizes'][$size]; ?>")'></div>&nbsp; &nbsp; &nbsp; &nbsp; </li>&nbsp; &nbsp; &nbsp; &nbsp; <?php&nbsp; &nbsp; }}?>
打开App,查看更多内容
随时随地看视频慕课网APP