Javascript 如何使用PHP显示前4行中的字段?
所以我使用的是ACF(高级自定义字段),我想显示前四行。虽然总共有20行,但我只需要显示前5行或后5行中的字段 而且,我的代码不需要在循环中,所以我愿意接受任何答案。我只将代码放在循环中,因为这是我知道如何显示repeater子字段的唯一方法。我对使用ACF字段非常陌生Javascript 如何使用PHP显示前4行中的字段?,javascript,php,wordpress,advanced-custom-fields,Javascript,Php,Wordpress,Advanced Custom Fields,所以我使用的是ACF(高级自定义字段),我想显示前四行。虽然总共有20行,但我只需要显示前5行或后5行中的字段 而且,我的代码不需要在循环中,所以我愿意接受任何答案。我只将代码放在循环中,因为这是我知道如何显示repeater子字段的唯一方法。我对使用ACF字段非常陌生 <?php // check if the repeater field has rows of data if( have_rows('repeat_field') ): // loop
<?php
// check if the repeater field has rows of data
if( have_rows('repeat_field') ):
// loop through the rows of data
while ( have_rows('repeat_field') ) : the_row();
// display a sub field value
the_sub_field('place_name');
the_sub_field('place_date');
the_sub_field('place_time');
endwhile;
else :
// no rows found
endif;
在完成所需的运行次数后,只需停止循环即可:
if( have_rows('repeat_field') ):
$i=0; // Counter to keep track of number of runs
while ( have_rows('repeat_field') ) : the_row();
the_sub_field('place_name');
the_sub_field('place_date');
the_sub_field('place_time');
$i++; // Increase the number by one after each run
if($i==4) break; // Stop after four runs
endwhile;
endif;