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

问题描述 投票:0回答:1

我正在使用ACF在Wordpress中的模板文件表中显示转发器字段。这些字段正在显示-但是该表似乎为每行创建一个新的“表”,而不是在同一表中同时包含两行子字段数据。

这是我的代码:

<?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>

这就是它的显示方式。我需要两行信息(电和电话行)都在第一个表中,而不是在单独的表中。Current display on page

wordpress html-table advanced-custom-fields repeater
1个回答
1
投票

while循环中的所有内容都对每个子字段重复。因此,您需要将输出内容限制为仅表行,并摆脱空行,例如:

<?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块。

© www.soinside.com 2019 - 2024. All rights reserved.