为什么这个PHP if语句仍包含内容?

时间:2015-04-06 02:51:34

标签: php

parts/lesson-links.php等于“提示”“主要课程”时,我希望get_the_lesson_contenttype()不被包括在内。

所以我这样做了:

  <h2><?php echo get_the_lesson_contenttype(); ?></h2>

  <?php if (get_the_lesson_contenttype() != 'Hints' || get_the_lesson_contenttype() != 'Main Lesson') { ?>
    <?php 
      include( locate_template( 'parts/lesson-links.php' ) );
    ?>
  <?php } ?>

但正如您在此页面中看到的那样:http://clo2015.chineselearnonline.com/lessoncontent/lesson-004-hints-and-tips/

parts/lesson-links.php仍在添加中。我做错了什么?

编辑:

奇怪的是,如果没有||,它只会添加Hint

  <?php if (get_the_lesson_contenttype() != 'Hints') include( locate_template( 'parts/lesson-links.php' ) );?>

1 个答案:

答案 0 :(得分:2)

你混淆了ANDSORS(双关语(我不好笑))

<h2>
    <?php echo get_the_lesson_contenttype(); ?>
</h2>

<?php 
    if (get_the_lesson_contenttype() != 'Hints' && get_the_lesson_contenttype() != 'Main Lesson') {
        include( locate_template( 'parts/lesson-links.php' ) );
    }
?>

让我们来看看一些布尔运算!在这里,我们gooooo .....

你说......

  

当get_the_lesson_contenttype()等于“Hint”或“Main Lesson”时,我希望不包含parts / lesson-links.php。

那就像......

if (get_the_lesson_contenttype() == "Hint" || get_the_lesson_contenttype() == "Main Lesson")
    DONT INCLUDE

激活NEGATION !!!!!!! (基本上翻转一切!)

if (get_the_lesson_contenttype() != "Hint" && get_the_lesson_contenttype() != "Main Lesson")
    DOOOO INCLUDE