2017-12-18 8 views
0

<?php if(have_rows('image_slideshow')): ?>でラップされたコードは、行が存在しないにもかかわらず出力されています(imageまたはcentered_textフィールドにはデータがありません)。このif文を構造化するにはどうすればよいのですか?イメージとセンタリングされたフィールドの一方または両方にデータがある場合にのみコードが出力されるのですか?文がまだ真ではないにもかかわらずコードを出力している場合

<?php if(have_rows('image_slideshow')): ?> 
    <div class="section-intro"> 
     <div class="slides owl-carousel"> 
      <?php while(have_rows('image_slideshow')): the_row(); 
       $image = get_sub_field('image'); 
       $content = get_sub_field('centered_text'); 
      ?> 
      <div class="slide intro" 
      <?php if(!empty($image)): ?> 
       style="background-image: url('<?php echo $image['url']; ?>')" 
      <?php endif; ?> 
      > 
       <?php echo $content; ?> 
      </div>   
      <?php endwhile; ?> 
     </div> 
    </div> 
<?php endif; ?> 

答えて

0

「image_slideshow」とは何ですか?変数ではありません。それは単なる文字列です。どうやらそれを明らかに関数has_rows()に入れることができますか?単なる文字列に行があることを確認するには?それは単純で常に真実です。

それは次のようになります。

<?php if(have_rows($variable_that_contains_the_rows)):?> 

それともこれ以上簡単な方法:

<?php if(count((array) $variable_that_contains_the_rows)): ?> 

私はしばらく後にこれを追加します。

<?php if(count((array) have_rows('image_slideshow'))): ?> 
+0

私はワードプレスを知らないもACFですが、マニュアル[have_rows()](https://www.advancedcustomfields.com/resources/have_rows/)から: 'have_rows($ field_name、$ post_id);' - > _ $ field_name:ループするリピータ/フレキシブルコンテンツフィールドの名前。例: "gallery_images"(必須)_。使用法: 'if(have_rows( 'parent_field')):[...]' – FirstOne

+0

いいえ。それから関数have_rows( 'image_slideshow'、$ the_id_of_the_slideshow) – Otvazhnii

+0

_' $ post_id':あなたの値が入力された特定の投稿ID。 **デフォルトは現在の投稿ID(必須ではありません)** ._私はわかりません... – FirstOne

関連する問題