【发布时间】:2018-06-18 21:43:54
【问题描述】:
我有一个名为“项目”的自定义帖子类型,并且我在我的 single-projects.php 中添加了灵活的字段内容。我正在尝试为位于主 header.php 中的每个项目添加一个英雄图像,因为我希望我的英雄图像位于导航后面。我一切正常,但我的英雄形象显示在 CPT 存档页面和 CPT 单页上,但我只想在每个项目页面上显示英雄形象。
在我的 header.php 文件中,我有:
<?php
// check if the flexible content field has rows of data
if( have_rows('project_flexible') ):
// loop through the rows of data
while ( have_rows('project_flexible') ) : the_row();
if( get_row_layout() == 'project_hero_image'):
$hero_image = get_sub_field('image'); ?>
<div class="hero-image"><img src="<?php echo $hero_image; ?>">
</div>
<?php
endif;
endwhile;
else :
// no layouts found
endif;
?>
【问题讨论】:
标签: php wordpress advanced-custom-fields