我正在使用以下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-statement的外观如何?
答案 0 :(得分:3)
你可以这样做:if ( in_array(get_post_type(), array('forum', 'topic', 'topic-tag') && in_array($post->ID, array($the_post_ID,$the_post_parent) )
答案 1 :(得分:1)
它看起来与你描述的完全一样:
if ((get_post_type() == 'forum' || get_post_type() == 'topic' ...) &&
(id == whatever || id == somethingelse))
echo "whatever"
请确保括号为您提供实际需要的优先级。
答案 2 :(得分:1)
if( in_array( ( $filter, array('forum','topic','topic-tag') && $global_post_id == $current_post_id ) || ( $global_post_id == $current_post_id ) )
您可以从模型或cfg等中拉出数组。
答案 3 :(得分:0)
就像你读它一样..
((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)