2017-12-16 9 views
1

$image$contentのいずれかが空でない場合は.section-introをページに出力する必要があります。両方が空の場合、.section-introは出力しないでください。何らかの理由で、少なくとも1つのフィールドが空ではないにもかかわらず、私のコードがページに何も出力していない。私が間違っていることを指摘してくれれば、非常に感謝しています。 OR2つの条件が真の場合divを表示

<?php if(!empty($image) && !empty($content)): ?> 

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

+1

ようcontinuosこと多分私はあなたをmissunderstandが、私はそれを読んで、あなたの説明は、それ自体に矛盾します。 _何らかの理由で、私のコードが少なくとも1つのフィールドが空ではないにもかかわらず、ページに何も出力していない "_ - それはまさに最初の文で記述したものですか? – Jeff

答えて

0

使用AND instandはまた、あなたの完全なコードは、この

<?php 
     if(have_rows('image_slideshow')): 
     $image = get_sub_field('image'); 
     $content = get_sub_field('centered_text'); 
    ?> 
    <?php if(!empty($image) && !empty($content)): ?> 
     <div class="section-intro"> 
     <div class="slides"> 
      <?php while(have_rows('image_slideshow')): the_row(); ?> 
      <div class="slide intro"> 
       <?php if(!empty($image)): ?> 
       <img src="<?php echo $image['url']; ?>"> 
       <?php endif; ?> 

       <?php echo $content; ?> 
      </div>   
      <?php endwhile; ?> 
     </div> 
    </div> 
    <?php endif ?> 
0

使用&のようにする必要があります||の代わりに

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

0

建設コードのショーは、この

<?php if(have_rows('image_slideshow')): 
     $image = get_sub_field('image'); 
     $content = get_sub_field('centered_text'); 

    if(!empty($image) || !empty($content)){ 

    echo "<div class='section-intro'> <div class='slides'>"; 
      while(have_rows('image_slideshow')) 
       the_row(); 
       echo " <div class='slide intro'> "; 
        if(!empty($image)) 
         echo "<img src= $image['url'] >"; 

        echo $content; 

    ?> 
       </div>   

      </div> 
     </div>