【问题标题】:ACF flexible content - image doesn't showACF 灵活内容 - 图像不显示
【发布时间】:2016-04-07 02:57:06
【问题描述】:

我正在处理 ACF Flexible 内容。我正在尝试在我的灵活内容中加载图像。但是图像没有显示,只是一个损坏的图标。
为什么?
我的子字段名为“照片”

            <h4 class="titrage2"><?php the_field('titre_1'); ?></h4>


                    <?php

                    if( have_rows('ateliers') ): ?>
                    <?php while ( have_rows('ateliers') ) : the_row(); ?>

                    <?php if( get_row_layout() == 'atelieratelier' ):?>

                                    <div id="article-atelier">
                                    <h4 class="titrage"><?php the_sub_field('atelier_01');?></h4>
                                    <div class="article-details"><?php the_sub_field('txtimg');?></div>         

                                    <div>
                                        <img src="<?php the_sub_field('photo'); ?>" />

                                    </div>

                                </div>

                           <?php  endif;?>

                        <?php  endwhile;?>

                     <?php else :?>


                    <?php endif;?>

【问题讨论】:

  • 你的问题是你把它设置为一个数组,并试图像一个 URL 一样拉进来。

标签: php image advanced-custom-fields


【解决方案1】:

这里是解决办法

 <?php 
        $image = get_sub_field('photo');
        if( !empty($image) ): ?>

            <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />

    <?php endif; ?>

【讨论】:

    猜你喜欢
    • 2016-04-07
    • 2018-05-31
    • 2020-07-10
    • 2017-01-07
    • 2016-02-01
    • 2018-01-10
    • 2013-12-29
    • 2022-11-14
    • 1970-01-01
    相关资源
    最近更新 更多