我有一个建筑项目的自定义帖子类型,其中包括一个ACF转发器,其中包含图像、标题和描述。此转发器在单个项目(post)页面上变成幻灯片。
每个项目也被分配到一个或多个类别(住房、医疗等)。在这些项目的类别页面上,我想下拉每个项目的第一个图像,用作缩略图。
类别模板中的代码如下所示:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<pre><?php print_r( get_field(\'images\') ) ?> </pre><!-- for debugging -->
<div class="col-xs-4 col-md-2">
<figure class="show-caption">
<?php if( have_rows(\'images\') ): the_row(); ?>
<?php $photo = get_sub_field(\'photo\'); $filename = $photo[\'sizes\'][\'large\']; ?>
<a href="<?php the_permalink() ?>" class="thumbnail"><img src="<?= $filename ?>" width="250" height="166" alt=""></a>
<?php endwhile; endif; ?>
</figure>
</div>
<?php endif; ?>
问题是,have_rows(\'images\')
在类别模板页面上返回false,但在项目页面上返回true。当我print_r( get_field(\'images\') )
在这两个页面上,我都在项目页面上获得了完整的图像数组,但在类别页面上只有一个整数(等于数组大小)。如何在分类页面上查看完整的图像阵列?