簡體   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