说明
屏幕截图
设置
子字段 定义一组可重复的子字段。 已折叠 通过指定要显示的单个子字段,可以折叠每一行。 最小行数 设置所需数据行数的限制。 最大行数 设置允许的数据行数限制。 布局 定义子字段外观的布局样式。
表 :子字段显示在表中。 标签将显示在表格标题中。
块 :子字段以块的形式依次显示。
排 :子字段显示在两列表中。 标签将出现在第一列。 按钮标签 “添加行”按钮中显示的文本。 分页 在ACF 6.0中添加。 定义在管理员中编辑转发器时,转发器是否应仅加载每页的设定行数。 如果禁用(默认情况下为禁用),则将立即加载所有行。 此设置不会影响模板的使用或通过REST API返回的结果。 注释 :当前在灵活内容和其他转发器字段中不支持此设置。 在这些情况下,此设置将不显示。 每页行数 在ACF 6.0中添加。 设置启用“分页”设置时页面上显示的行数。
模板使用
基本回路
<? php(电话) //检查行是否存在。 if(have_rows('repeater_field_name')): //在行之间循环。 while(have_rows('repeater_field_name')):the_row(); //加载子字段值。 $sub_value=get_sub_field('sub_field'); //做一些事情,但如果直接输出,请确保转义该值。。。 //结束循环。 endwhile; //没有价值。 其他: //做点什么。。。 endif;
显示滑块
<? php if(have_rows('slides')):?> <ul class=“幻灯片”> <? php while(have_rows('slides')):the_row(); $image=获取子字段('image'); ?> <li> <? php-echo wp_get_attachment_image($image,'full');?> <p><? php-echo acf_esc_html(get_sub_field('caption'));?></ p>(第页) </li> <? php endwhile;?> </ul> <? php-endif;?>
Foreach循环
<? php(电话) $rows=获取字段('repeater_field_name'); if($rows){ echo'<ul class=“slides”>'; foreach($rows作为$row){ $image=$row['image']; echo“<li>”; echo wp_get_attachment_image($image,'full'); echo wp_kses_post(wpautop($row[‘caption’])); echo“</li>”; } echo“</ul>”; }
嵌套循环连接
<? php(电话) /** *字段结构: * *-parent_repeater(中继器) *-parent_title(文本) *-child_repeater(中继器) *-child_title(文本) */ if(have_rows(“父转发器”): while(have_rows('parent_reporter')):the_row(); //获取父值。 $parent_title=获取子字段(“父标题”); //在子转发器行上循环。 if(have_rows('child_reporter')): while(have_rows('child_reporter')):the_row(); //获取子值。 $child_title=获取子字段('child_ttitle'); endwhile; endif; endwhile; endif;
访问第一行值
<? php(电话) $rows=获取字段('repeater_field_name'); if($rows){ $first_row=$行[0]; $first_row_title=$first_ row[标题]; //做点什么。。。 }
<? php(电话) if(have_rows('repeater_field_name')){ while(have_rows('repeater_field_name')){ row(); $first_row_title=获取子字段('title'); //做点什么。。。 断裂; } }
访问随机行值
<? php(电话) $rows=获取字段('repeater_field_name'); if($rows){ $index=array_rand($rows); $rand_row=$rows[$index]; $rand_row_title=$rand_row[“标题”]; //做点什么。。。 }