我有一个名为“项目”的自定义帖子类型,并且我在我的单个项目中添加了灵活的字段内容。php。我试图为主标题中的每个项目添加一个英雄形象。php,因为我希望我的英雄形象坐在导航后面。我有一切工作,但我的英雄形象是显示在CPT存档页面和CPT单页,但我只想在每个项目页面上显示英雄形象。
在我的标题中。我拥有的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;
?>