我刚刚开始使用ACF转发器字段类型在我的网站上显示项目网格。转发器字段命名为" projects"我正在使用get子字段来显示内容。但是没有显示内容,图像仅显示为图像路径。我已经拥有了我需要它们显示的字段的样式。
<?php if (have_rows('projects')): ?>
<div class="section group project-grid"><!-- start of grid row-->
<div class="col span_1_of_4">
<img class="inner-line-break" src="<?php bloginfo('template_directory')?>/images/bio.png" />
</div>
<div class="col span_1_of_4 project-data-title">
<p class="project-name"><?php the_sub_field ('name'); ?></p>
<p>Programme:<br /><?php the_sub_field ('programme'); ?></p>
</div>
<div class="col span_1_of_4 project-data">
<p>Website:<br /><a href="http://www.eurobioimaging.eu"><?php the_sub_field ('website'); ?></a></p>
</div>
<div class="col span_1_of_4 project-data">
<p>Services:<br /> <p><?php the_sub_field ('services_icons'); ?></p>
<p><a href="#" data-tooltip="Proposal Writing"><i class="fa fw fa-clone hover-icon"></i></a> <a href="#" data-tooltip="Contract Negotiations"><i class="fa fw fa-file-text-o hover-icon"></i></a> <a href="#" data-tooltip="Project Management"> <i class="fa fw fa-calendar-check-o hover-icon"></i></a></p> </p>
</div>
</div>
</div> <!--end of grid row-->
<?php endif; ?>
答案 0 :(得分:1)
您只测试是否有行,但您实际上没有迭代它们并填充变量(使用the_row())。试试这样:
while ( have_rows('projects') ) : the_row();
the_sub_field('sub_field_name');
endwhile;
答案 1 :(得分:0)
固定代码:
<?php if(have_rows('projects')) : while (have_rows('projects')) : the_row();
$name = get_sub_field('name');
$programme = get_sub_field('programme');
$website = get_sub_field('website');
$services = get_sub_field('services_icons');
?>
<div class="section group project-grid"><!-- start of grid row-->
<div class="col span_1_of_4">
<img src="<?php echo $logo['url']; ?>" alt="<?php echo $logo['alt'] ?>" />
</div>
<div class="col span_1_of_4 project-data-title">
<p class="project-name"><?php echo $name; ?></p>
<p>Programme:<br /><?php echo $programme; ?></p>
</div>
<div class="col span_1_of_4 project-data">
<p>Website:<br /><a href="http://www.eurobioimaging.eu"><?php echo $website; ?></a></p>
</div>
<div class="col span_1_of_4 project-data">
<p>Services:<br /> <p><?php echo $$services; ?></p>
<p><a href="#" data-tooltip="Proposal Writing"><i class="fa fw fa-clone hover-icon"></i></a> <a href="#" data-tooltip="Contract Negotiations"><i class="fa fw fa-file-text-o hover-icon"></i></a> <a href="#" data-tooltip="Project Management"> <i class="fa fw fa-calendar-check-o hover-icon"></i></a></p> </p>
</div>
</div><?php endwhile; endif; ?>
</div> <!--end of grid row-->