Php 是否有一种方法可以使用Wordpress高级自定义字段(ACF)从特定行开始?
所以我在Wordpress中使用ACF(高级自定义字段)。我有大约40行要显示,但我想从第5行开始。基本上,我想将第5行显示到第40行,而不是从第一行开始。有办法做到这一点吗?我的代码如下Php 是否有一种方法可以使用Wordpress高级自定义字段(ACF)从特定行开始?,php,wordpress,advanced-custom-fields,Php,Wordpress,Advanced Custom Fields,所以我在Wordpress中使用ACF(高级自定义字段)。我有大约40行要显示,但我想从第5行开始。基本上,我想将第5行显示到第40行,而不是从第一行开始。有办法做到这一点吗?我的代码如下 <?php if( have_rows('repeat_field') ): $i = 0; // loop through the rows of data while ( hav
<?php
if( have_rows('repeat_field') ):
$i = 0;
// loop through the rows of data
while ( have_rows('repeat_field') ) : the_row();
$i++;
if (!empty(get_sub_field('feature_image_post'))) {
the_sub_field('feature_article_link');
the_sub_field('feature_image_post');
the_sub_field('feature_title');
}
if( $i > 40 )
{
break;
}
endwhile;
else :
// no rows found
endif;
?>
您应该能够使用以下代码实现这一点:
<?php
$repeat = get_field('repeat_field');
for ($i = 5; $i <= 40; $i++) {
if (!empty($repeat[$i]['feature_image_post'])) {
echo $repeat[$i]['feature_article_link'];
echo $repeat[$i]['feature_image_post'];
echo $repeat[$i]['feature_title'];
}
}
?>
只需使用
get_field
获取中继器的数组,然后使用PHP中的for
函数循环第5到第40个您应该能够使用如下代码实现此目的:
<?php
$repeat = get_field('repeat_field');
for ($i = 5; $i <= 40; $i++) {
if (!empty($repeat[$i]['feature_image_post'])) {
echo $repeat[$i]['feature_article_link'];
echo $repeat[$i]['feature_image_post'];
echo $repeat[$i]['feature_title'];
}
}
?>
只需使用
get_field
获取中继器的数组,然后使用PHP中的for
函数循环第5次到第40次您应该在循环中使用continue语句跳过迭代,如下所示:
<?php
if( have_rows('repeat_field') ):
$i = 0;
// loop through the rows of data
while ( have_rows('repeat_field') ) : the_row();
$i++;
if($i<5)
continue;
if (!empty(get_sub_field('feature_image_post')))
{
the_sub_field('feature_article_link');
the_sub_field('feature_image_post');
the_sub_field('feature_title');
}
if( $i > 40 )
{
break;
}
endwhile;
else :
// no rows found
endif;
?>
您应该在循环中使用continue语句跳过迭代,如下所示:
<?php
if( have_rows('repeat_field') ):
$i = 0;
// loop through the rows of data
while ( have_rows('repeat_field') ) : the_row();
$i++;
if($i<5)
continue;
if (!empty(get_sub_field('feature_image_post')))
{
the_sub_field('feature_article_link');
the_sub_field('feature_image_post');
the_sub_field('feature_title');
}
if( $i > 40 )
{
break;
}
endwhile;
else :
// no rows found
endif;
?>
谢谢。这正是我要找的!谢谢这正是我要找的!