2017-06-13 5 views
0

私はWordpressでACF(高度なカスタムフィールド)を使用しています。表示する列は約40行ですが、5行目から開始したいと考えています。基本的には、1行目ではなく40行目に5行目を表示したいとします。これを行う方法はありますか?私のコードは以下の通りです。Wordpress Advanced Custom Fields(ACF)を使用して特定の行を開始する方法はありますか?

あなたはこのように、この使用してコードを達成することができるはず
  <?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; 

      ?> 

答えて

1

第40回:

<?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; 
?> 
+0

ありがとうございます。これはちょうど私が探していたものでした! – Mariton

+0

あなたは大歓迎です! –

1

<?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を使用し、その後に第5回をループにPHPでfor機能を使用しますあなたは以下のように反復をスキップするためにあなたのループ内のステートメントを継続使用する必要があります

関連する問題