在 PHP 循环中添加中断后如何继续操作?

How do you continue an action after you add a break in a PHP Loop?

问题来了。我有两个 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 模板文件中:

您的 have_rows 实习循环,您可以轻松地继续循环您的行。

这是一个代码:

/*** One.php  ***/
<?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 >= 77 )
      {
          break;
      }
      endwhile;
  else :
      // no rows found
  endif;
?>


 /*** Two.php  ***/
<?php
  if( have_rows('repeat_field') ):
    // 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 >= 100 )
      {
          break;
      }


      endwhile;
  else :
      // no rows found
  endif;
?>