ACF中继器显示行号

Phi*_*hil 0 repeater rows count advanced-custom-fields

希望显示每个中继器行的单独编号。例如,第一行将显示“1”,第二行将显示“2”。

我从艾略特那里找到了这个,

<?php echo count( get_field('repeater_field') );?>
Run Code Online (Sandbox Code Playgroud)

它计算总共有多少行。但我需要每个旁边的个人号码。

谢谢

Joe*_*Joe 6

我建议在这里看看 Elliot 的回答:

http://support.advancedcustomfields.com/forums/topic/getting-instance-and-sort-of-id-of-repeater-field/

您可能想要设置一个计数器变量 ( $i ),然后在循环内将 1 添加到 $i 。

<?php if( have_rows('repeater_field') ): $i = 0; ?>
    <div class="repeater_loop">
    <?php while( have_rows('repeater_field') ): the_row(); $i++; ?>
        <p>This is row number <?php echo $i; ?>.</p>
        <!-- call your sub_fields as needed -->
    <?php endwhile; ?>
    </div>
<?php endif; ?>
Run Code Online (Sandbox Code Playgroud)

这将输出一个带有显示行号的段落标记的 div。