【发布时间】:2017-06-14 19:01:36
【问题描述】:
所以这就是问题所在。我有两个 PHP 文件(one.php 和 two.php)。第一个循环从 0 开始,到 77 结束。
下一个循环从第 78 行开始,在第 300 行停止。这部分有效。由于某种原因, two.php 中的所有行都没有显示。我认为 one.php 的循环正在阻止 two.php 完全运行。我在 WordPress 中使用高级自定义字段 (ACF)。
/*** One.php ***/
<?php
if( have_rows('repeat_field') ):
$i = 0;
// loop through the rows of data
while ( have_rows('repeat_field') ) : the_row();
$i++;
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 > 77 )
{
break;
}
endwhile;
else :
// no rows found
endif;
?>
/*** Two.php ***/
<?php
if( have_rows('repeat_field') ):
$i = 0;
// loop through the rows of data
while ( have_rows('repeat_field') ) : the_row();
$i++;
if($i<79)
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 > 100 )
{
break;
}
endwhile;
else :
// no rows found
endif;
?>
这两个文件都包含在一个 PHP 模板文件中:
【问题讨论】:
-
也许你不需要
continue -
@Sysix 好的,你有替代方案或建议吗?
-
告诉我应该输出哪些行?使用
$i变量作为计数器;) -
我不明白为什么第一个循环应该在 77 之后停止 - 它不应该做任何有趣的事情,因为在第 8 行周围有
continue。第二个应该从 79 运行到 100,因为休息。第二件事 - 你想达到什么目的? -
那么,如果你想要
77,为什么还有if( $i > 40 )?为什么第 8 行有continue- 你怎么期望第 9 行这样一个被执行?
标签: php wordpress advanced-custom-fields