繁体   English   中英

一个带有三个'||'的php if语句 '&&',然后是'||'?

[英]An php if-statement with three '||' an '&&' and then an '||'?

我正在使用以下if语句将一个类添加到列表项:

<?php
     global $post;
     $the_post_parent = $post->post_parent;
     $the_post_ID = $post->ID;
     $bbp_forums = get_posts('post_type=forum&orderby=title&order=asc&posts_per_page=-1&order=ASC');
?>

<li <?php if ( $post->ID == $the_post_ID || $post->ID == $the_post_parent ) echo 'class="current"'; ?>>

在这种情况下,如果全局帖子ID与当前帖子ID匹配,则回显类.current

我想在语句中再添加三个条件:

仅在当前帖子类型为论坛主题主题标签时才执行回显:

'forum' == get_post_type() 
'topic' == get_post_type() 
'topic-tag' == get_post_type()

因此,在这一点上,应阅读:

如果...

当前帖子类型论坛主题主题标签及其

全局帖子ID等于当前帖子ID

全局帖子ID等于当前的父帖子

回响全班。

该if语句的外观如何?

您可以执行以下操作: if ( in_array(get_post_type(), array('forum', 'topic', 'topic-tag') && in_array($post->ID, array($the_post_ID,$the_post_parent) )

它看起来与您描述的完全一样:

if ((get_post_type() == 'forum' || get_post_type() == 'topic' ...) &&
    (id == whatever || id == somethingelse))
      echo "whatever"

只要确保括号为您提供了实际需要的优先级即可。

if( in_array( ( $filter, array('forum','topic','topic-tag') && $global_post_id == $current_post_id ) || ( $global_post_id == $current_post_id ) )

您可以从模型或cfg等提取数组。

就像你读的时候一样。

((current post type is a forum OR topic OR topic tag )
AND
(its global post id is equal to the current post id))
OR
(the global post id is equal to the current post parent)

暂无
暂无

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

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