问题:如何简单地计算 ACF 重复器字段输出中的行数?
Goal:当只有一行和多行时,使 css 类的输出看起来有所不同。
My code:
if( have_rows('testimonials')) {
$counter = 0;
$numtestimonials = '';
//loop thru the rows
while ( have_rows('testimonials') ){
the_row();
$counter++;
if ($counter < 2) {
$numtestimonials = 'onlyone';
}
echo '<div class="testimonial ' . $numtestimonials . '">';
// bunch of output here
echo '</div>';
}
}
显然,我在这里执行的方法将不起作用,因为第一次通过该行时计数
谢谢你!
好吧,我终于找到了这个问题的答案。
计算 ACF 中继器中总行数的方法是:
$numrows = count( get_sub_field( 'field_name' ) );
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)