ACF中继器显示行号
ACF Repeater display row number
希望显示每个转发器行的单独编号。例如,第一行将显示“1”,第二行将显示“2”。
这是我从 Elliot 那里找到的,
<?php echo count( get_field('repeater_field') );?>
计算总共有多少行。但我需要每个旁边的个人编号。
谢谢
我建议在这里看看 Elliot 的回答:
您可能想要设置一个计数器变量 ( $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 和一个显示行号的段落标记。
<?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; ?>
已有 get_row_index() 可用。
希望显示每个转发器行的单独编号。例如,第一行将显示“1”,第二行将显示“2”。
这是我从 Elliot 那里找到的,
<?php echo count( get_field('repeater_field') );?>
计算总共有多少行。但我需要每个旁边的个人编号。
谢谢
我建议在这里看看 Elliot 的回答:
您可能想要设置一个计数器变量 ( $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 和一个显示行号的段落标记。
<?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; ?>
已有 get_row_index() 可用。