Как продолжить действие после добавления перерыва в цикле PHP?

Так вот в чем проблема. У меня есть два PHP-файла (one.php и two.php). Первый цикл начинается с 0 и заканчивается на 77.

Следующий цикл начинается со строки 78 и заканчивается на 300. Это частично работает. По какой-то причине все строки из two.php не отображаются. Я полагаю, что цикл one.php не позволяет полностью запустить two.php. Я использую расширенные настраиваемые поля (ACF) в WordPress.

 /*** 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:

1 ответ

Решение

Ваш стажер 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;
?>
Другие вопросы по тегам