Mak*_*aki 3 php wordpress advanced-custom-fields
我使用中继器布局创建了一个自定义字段来添加一些输入文本。我想显示所有的值。我在 ACF 文档上找到了一些代码,但我无法理解它是如何工作的
<?php
$rows = get_field('repeater_field_name');
if($rows)
{
echo '<ul>';
foreach($rows as $row)
{
echo '<li>sub_field_1 = ' . $row['sub_field_1'] . ', sub_field_2 = ' . $row['sub_field_2'] .', etc</li>';
}
echo '</ul>';
}
?>
Run Code Online (Sandbox Code Playgroud)
http://www.advancedcustomfields.com/resources/repeater/
我不知道将使用 Repeater 创建多少字段,并且我想使用 foreach 循环所有值。那可能吗?
先感谢您
foreach版本:
<?php
$rows = get_field('repeater');
if($rows)
{
echo '<ul>';
foreach($rows as $row)
{
echo '<li>sub_field_1 = ' . $row['text'] . '</li>';
}
echo '</ul>';
}
Run Code Online (Sandbox Code Playgroud)
同时版本:
<?php
// check if the repeater field has rows of data
if( have_rows('repeater') ):
// loop through the rows of data
while ( have_rows('repeater') ) : the_row();
// display a sub field value
the_sub_field('text');
endwhile;
else :
echo 'nothing found';
endif;
?>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
26922 次 |
| 最近记录: |