【问题标题】:ACF Repeater in Wordpress not showing imagesWordpress 中的 ACF 中继器不显示图像
【发布时间】:2016-10-26 19:26:59
【问题描述】:

我无法在 Wordpress 中使用中继器显示图像。 出于某种原因,它只显示替代文本而不是图像本身? example

上面的图片是我的缩略图帖子,并且显示正确。 有谁知道这是什么原因造成的?

我的代码

   <div class="row">
    <div class="col-sm-6 left"><h1>COMMERCIAL</h1><br>
       <div class="page-header">

        <?php $mymovies = new WP_Query(array(
          'post_type' => 'my_movies'
          )); ?>

          <?php while($mymovies->have_posts()) : $mymovies->the_post(); ?>
            <div class="movie-colums">
             <div class="thumbtitle group">
                <div class="preview">
                   <?php the_post_thumbnail('thumbnail'); ?>
                   <h1><?php the_title(); ?><br>
                      <?php the_field('year'); ?>   
                      <?php
                      // check if the repeater field has rows of data
                      if( have_rows('images_rep') ):
                        // loop through the rows of data
                        while ( have_rows('images_rep') ) : the_row();
                    // display a sub field value
                    the_sub_field('image');
                    endwhile;
                    else :
                       // no rows found
                        endif;
                    ?>                                  
                </h1>
            </div>

        </div>
    </div>
 <?php endwhile; ?>
</div>

提前致谢

【问题讨论】:

    标签: php wordpress custom-post-type advanced-custom-fields


    【解决方案1】:

    你的转发器的 PHP 位应该是:

    <?php if( have_rows('images_rep') ): ?>
    
        <?php while( have_rows('images_rep') ): the_row(); 
            $image = get_sub_field('image');
        ?>
    
            <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>">
    
        <?php endwhile; ?>
    
    <?php endif; ?>
    

    看起来您的示例正在输出图像对象,因此只需将图像 URL 包装在图像标记中即可。

    参考:https://www.advancedcustomfields.com/resources/image/

    【讨论】:

    • @AlfredKwak 现在检查一下。我做了一些编辑。同时使用完整的新代码更新您的第一篇文章。
    • 查看我的新更新。用我所做的完全替换你的中继器循环。您将包括整个图像对象,而不仅仅是 URL。
    • 哈抱歉!我的错!它现在正在工作! :) 感谢您的时间和精力!非常感谢
    • 欢迎您@AlfredKwak 请投票并将此答案标记为正确:)
    猜你喜欢
    • 2022-12-05
    • 2018-04-11
    • 2019-02-03
    • 2016-07-02
    • 2017-01-01
    • 2015-06-12
    • 2022-10-02
    • 2014-09-22
    • 2013-11-19
    相关资源
    最近更新 更多