table 中的 ACF 转发器字段 - 在 PHP 模板中

ACF Repeater Fields in table - Within PHP Template

我正在使用 ACF 在我的 Wordpress 模板文件的 table 中显示转发器字段。字段正在显示 - 然而 table 似乎为每一行创建一个新的 "table",而不是在同一 table 中包含两行子字段数据。

这是我的代码:

<?php if(get_field('monthly_expenses')): ?>

<ul>

<?php while(has_sub_field('monthly_expenses')): ?>

<table>
<tbody>
<tr>
<td><strong>&nbsp;Monthly Expense</strong></td>
<td><strong>Estimated Amount</strong></td>
<td><strong>Registered Supplier</strong></td>
</tr>
<tr>
<td><?php the_sub_field('monthly_expense'); ?></td>
<td><?php the_sub_field('estimated_amount'); ?></td>
<td><?php the_sub_field('registered_supplier'); ?></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
<!-- DivTable.com -->


<?php endwhile; ?>

</ul>

这是它的显示方式。我需要将两行信息(电力行和电话行)都放在第一个 table 中,而不是单独的 table 中。

while 循环中的所有内容都针对每个子字段重复。因此,您需要将输出限制为仅 table 行并像这样删除空行:

<?php if(get_field('monthly_expenses')): ?>

<ul>
<table>
<tbody>
<tr>
<td><strong>&nbsp;Monthly Expense</strong></td>
<td><strong>Estimated Amount</strong></td>
<td><strong>Registered Supplier</strong></td>
</tr>

<?php while(has_sub_field('monthly_expenses')): ?>

<tr>
<td><?php the_sub_field('monthly_expense'); ?></td>
<td><?php the_sub_field('estimated_amount'); ?></td>
<td><?php the_sub_field('registered_supplier'); ?></td>
</tr>
<!-- DivTable.com -->

<?php endwhile; ?>
</tbody>
</table>

</ul>

我把 <ul> 留在了那里,但是我不知道那最初是做什么用的。另外,我希望你关闭了 if 块。