【问题标题】:ACF Repeater display row numberACF 中继器显示行号
【发布时间】:2016-07-02 05:32:12
【问题描述】:

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

我从 Elliot 那里找到的,

<?php echo count( get_field('repeater_field') );?>

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

谢谢

【问题讨论】:

  • 您是否有任何代码示例说明您如何尝试使用它?我建议在您的 while 循环上方创建一个变量(等于零),并在循环内向该变量添加 1。这可以让您计算出您正在循环的商品,但如果您使用任何东西来随机化您的订单,则不会显示它是否是管理员中的第 3 项,而只是屏幕上的第 3 项。跨度>

标签: count repeater rows advanced-custom-fields


【解决方案1】:

我建议在这里看看 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; ?>

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

【讨论】:

  • 感谢您的帮助!
【解决方案2】:
<?php if( have_rows('tabel_produse_profit') ): $i = 0; ?>

<table width="100%" class="tab">
  <tr>
    <td>Nr.</td>
    <td>Imagine</td>
    <td>Nume</td>
    <td>Evaluare</td>
    <td>Verificati pretul</td>
  </tr>

    <?php while( have_rows('tabel_produse_profit') ): the_row(); $i++;
        // vars
        $image = get_sub_field('tabel_imagine_produs');
        $link = get_sub_field('tabel_link_profit');
        $titlu = get_sub_field('tabel_titlu_profit');
        $evaluare = get_sub_field('tabel_evaluare');
        $count = count(get_field('tabel_produse_profit'));
        ?>
        <tr>
            <td class="row1">
            <?php echo $i; ?>
                <?php if( $count ): ?>
                    <div class="rowc"> din <?php echo $count; ?></div>
                <?php endif; ?>
            </td>
           <td class="row2">
                <?php if( $image ): ?>
                    <img class="imag" src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" />
                <?php endif; ?>
           </td>
           <td class="row3">
                <?php if( $titlu ): ?>
                    <h2><?php echo $titlu; ?></h2>
                <?php endif; ?>
           </td>
           <td class="row4">
                <?php if( $evaluare ): ?>
                    <div class="eva"><?php echo $evaluare; ?></div>
                <?php endif; ?>
           </td>
           <td class="row5">
                <?php if( $link ): ?>
                    <a class="ver" href="<?php echo $link; ?>">VERIFICAȚI PREȚUL</a>
                    <div class="mag">pe emag.ro</div>
                <?php endif; ?>
           </td>
            <?php echo $content; ?>
        </tr>
      <?php endwhile; ?>  
    </table>
<?php endif; ?>

【讨论】:

    【解决方案3】:

    get_row_index() 已经可以使用了。

    【讨论】:

      猜你喜欢
      • 2017-01-01
      • 2019-10-16
      • 2018-04-11
      • 2016-12-07
      • 2022-12-05
      • 2013-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多