简体   繁体   English

如果还是不起作用

[英]If OR not working

I have a statement set up to determine whether drupal blocks are present, and give a class depending on how many blocks are available. 我有一条语句来确定是否存在drupal块,并根据可用的块数给出一个类。

<?php if($page['sidebar_first'] || $page['sidebar_second']) { 
      $contentwid= "eleven"; 
 } else { 
      $contentwid= "sixteen"; 
 } ?>

<?php if($page['sidebar_first'] && $page['sidebar_second']) { 
      $contentwid= "seventeen"; 
 } else { 
      $contentwid= "sixteen"; 
 } ?>

<div id="content" class="<?php print $contentwid; ?> columns">
</div>

The second statement works fine, If there is a block in the first sidebar AND a block in the second sidebar, then the main content has a class of seventeen. 第二个语句工作正常,如果第一个侧边栏中有一个块,而第二个侧边栏中有一个块,则主要内容的类为17。

The problem is with the first statement for OR ( || ). 问题在于OR(||)的第一个语句。 It doesn't matter if there is a block in either sidebar, the content is always given a class of sixteen, which is full width, and pushes the sidebar content to the bottom. 侧边栏中是否有块都无关紧要,始终将内容的类别设为16,即全角,并将侧边栏内容推到底部。

I know its detecting sidebar blocks correctly because the second statement works perfectly. 我知道它可以正确检测到侧边栏,因为第二条语句可以正常工作。 I have set up everything else correctly, and have traced it back to this OR statement, which always seems to result in FALSE (sixteen). 我已经正确设置了所有其他内容,并将其追溯到此OR语句,该语句似乎总是导致FALSE(十六)。

I've tried || 我尝试过|| and OR, but as far as I know, they are no different, just user preference right? 和OR,但据我所知,它们没有什么不同,只是用户偏好设置正确吗?

I'm stumped. 我很沮丧

It's executing the first if (the or ) and setting $contentwid correctly, but then it still executes the second if (the and ) and failing, so executing the else for that, which resets $contentwid to "sixteen" 它正在执行第一个if (the or )并正确设置$contentwid ,但随后它仍将执行第二个if (the and )并失败,因此为此执行else ,这会将$contentwid重置$contentwid “十六”

<?php if($page['sidebar_first'] || $page['sidebar_second']) { 
      $contentwid= "eleven"; 
 } else { 
      $contentwid= "sixteen"; 
 } elseif($page['sidebar_first'] && $page['sidebar_second']) { 
      $contentwid= "seventeen"; 
 } else { 
      $contentwid= "sixteen"; 
 } ?>

though you might want to reverse the "and" and "or" to prevent the and from failing 尽管您可能想反转“ and”和“ or”以防止and失败

 <?php if($page['sidebar_first'] && $page['sidebar_second']) { 
      $contentwid= "seventeen"; 
 } elseif($page['sidebar_first'] || $page['sidebar_second']) { 
      $contentwid= "eleven"; 
 } else { 
      $contentwid= "sixteen"; 
 } ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM