Php ACF中继器字段不同计数
我有一段代码:Php ACF中继器字段不同计数,php,wordpress,advanced-custom-fields,Php,Wordpress,Advanced Custom Fields,我有一段代码: <?php if( have_rows('our_people') ): $i = 0; while ( have_rows('our_people') ) : the_row(); ?> <?php $i++; ?> <?php if( $i > 3 ): break; ?> <?php endif; ?> <a class="people-thumb fancybox
<?php
if( have_rows('our_people') ):
$i = 0;
while ( have_rows('our_people') ) : the_row(); ?>
<?php $i++; ?>
<?php if( $i > 3 ):
break; ?>
<?php endif; ?>
<a class="people-thumb fancybox-inline" href="#fancybox-<?php echo $i;?>">
<div class="people-thumb-image" style="width:172px;height:172px;overflow:hidden;background:transparent url(<?php the_sub_field('people_image'); ?>) no-repeat center center; background-size:cover;"></div>
<div class="people-thumb-details">
<h3><?php the_sub_field('people_name_acf'); ?></h3>
<p><?php the_sub_field('people_title'); ?></p>
</div>
</a>
<div class="peopleoverlay">
<div id="fancybox-<?php echo $i;?>">
<img src="<?php the_sub_field('people_image'); ?>" width="172" style="float:left;margin:0 10px 10px 0;"> <?php the_sub_field('people_details'); ?>
</div>
</div>
<?php endwhile;
else :
endif;
?>
这是什么,它只是计数的条目,然后停止后3-工程罚款
但是,对于3之后的repeater字段中的其他行,如何使它们也显示出来?原因是这3个条目位于一个单独的样式分区中,而所有其他条目都位于另一个分区中
然而,如果我试图重复这段代码,什么也看不出来。所以我必须以某种方式重置它?我希望3之后的所有中继器行都显示在不同的部分。看起来您的代码明确要求不要显示超过3个结果!注释如下
$i = 0; // Start a counter
while ( have_rows('our_people') ) : the_row(); ?> // As long as there are posts to display
<?php $i++; ?> // increment the counter
<?php if( $i > 3 ): // if the counter is 4 or more...
break; ?> // don't execute the code below; jump out of the while loop.
<?php endif; ?>
这将允许ACF显示存储在该元字段中的所有人员
但是,如果要向第4个div及其后添加其他类,请更改条件,删除break语句,并将结果包装到标识它的div中
<?php $i++; ?>
<?php if( $i > 3 ): ?>
<div class="other-style">
<?php endif; ?>
然后,你必须在最后用另一张支票结账
...
<?php if( $i > 3 ): ?>
</div> <!-- .other-style -->
<?php endif; ?>
...
<?php if( $i > 3 ): ?>
</div> <!-- .other-style -->
<?php endif; ?>