如果两个条件为真,则隐藏div

时间:2017-12-16 10:44:35

标签: php wordpress advanced-custom-fields

如果$image$content中的任何一个不为空.section-intro,则应输出到该页面。即如果两者都为空.section-intro则不应输出。由于某些原因,尽管至少有一个字段不为空,但我的代码不会输出任何内容。关于我做错的任何指示都将不胜感激。



<?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; ?>
&#13;
&#13;
&#13;

3 个答案:

答案 0 :(得分:0)

使用AND

OR个instand
<?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 ?>

答案 1 :(得分:0)

使用&amp;&amp;而不是||

&#13;
&#13;
<?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; ?>
&#13;
&#13;
&#13;

答案 2 :(得分: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>