我正在使用ACF在Wordpress中的模板文件表中显示转发器字段。这些字段正在显示-但是该表似乎为每行创建一个新的“表”,而不是在同一表中同时包含两行子字段数据。
这是我的代码:
<?php if(get_field('monthly_expenses')): ?>
<ul>
<?php while(has_sub_field('monthly_expenses')): ?>
<table>
<tbody>
<tr>
<td><strong> 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> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</tbody>
</table>
<!-- DivTable.com -->
<?php endwhile; ?>
</ul>
while
循环中的所有内容都对每个子字段重复。因此,您需要将输出内容限制为仅表行,并摆脱空行,例如:
<?php if(get_field('monthly_expenses')): ?>
<ul>
<table>
<tbody>
<tr>
<td><strong> 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
块。