【问题标题】:ACF Repeater Fields in table - Within PHP Template表中的 ACF 中继器字段 - 在 PHP 模板中
【发布时间】:2020-07-21 21:23:00
【问题描述】:

我正在使用 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>

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

【问题讨论】:

    标签: wordpress html-table advanced-custom-fields repeater


    【解决方案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>
    

    我已经把&lt;ul&gt; 留在了那里,但是我不知道它最初的用途。另外,我希望你关闭if 块。

    【讨论】:

      猜你喜欢
      • 2019-03-30
      • 2017-01-01
      • 2014-09-22
      • 2018-07-17
      • 1970-01-01
      • 2018-04-11
      • 2013-12-29
      • 2015-03-30
      • 1970-01-01
      相关资源
      最近更新 更多