【发布时间】:2017-05-17 14:03:23
【问题描述】:
我需要在输入的每对 ACF 转发器字段周围添加一个 div。 我有这个代码的 sn-p,它为每三个字段完成这项工作。每次我更改数字时,它都会使下一个 div ID 成为前一个的子 ID。 任何建议都会很棒!谢谢
// check if the repeater field has rows of data
if( have_rows('services') ):
// loop through the rows of data
// add a counter
$count = 0;
$group = 0;
while ( have_rows('services') ) : the_row();
// vars
$teacher_bio = get_sub_field('service_title');
$teacher_name = get_sub_field('service_information');
$teacher_image = get_sub_field('icon');
if ($count % 3 == 0) {
$group++;
?>
<div id="services-<?php echo $group; ?>" class="cf group-<?php echo $group; ?>">
<?php
}
?>
<div class="service">
<img src="<?php the_sub_field('icon'); ?>" />
<p><?php echo $teacher_name; ?></p>
<?php echo $teacher_bio; ?>
</div><!-- .teacher -->
<?php
if ($count % 3 == 2) {
?>
</div><!-- #services -->
<?php
}
$count++;
endwhile;
else :
// no rows found
endif;
【问题讨论】:
-
如果您的中继器中只有一个中继器,这不是更简单吗?那么每个“教师/服务”都会有一行,您可以将其包装在您想要的任何 html 中
标签: wordpress advanced-custom-fields