[英]Wordpress if is page and in category question
I can't seem to find an answer to this question anywhere, so I'm wondering if anyone might be able to help? 我似乎在任何地方都找不到这个问题的答案,所以我想知道是否有人可以提供帮助?
How do I combine the is_page and in_category clause? 如何合并is_page和in_category子句?
At the moment, home-2 (the slug) doesn't seem to want to work. 目前,home-2(子弹)似乎不想工作。
<?php if(is_page( 'Home' )) { ?>
<?php } elseif (is_page('home-2')) { ?>
<?php } elseif (in_category('projects')) { ?>
<?php } else { ?>
<?php } ?>
Thanks. 谢谢。
In Condition '&&' is 'AND' and '||' 在条件中,“ &&”是“ AND”和“ ||” is 'OR'.
是“ OR”。 Use this and combine many clause.
使用这个并结合许多子句。
if(is_page('home-2') && in_category('projects')){
OR
if(is_page('home-2') || in_category('projects')){
//Your Statement here
}
If you want to combine conditions in an if
-clause you can either join them with &&
(evaluates as and ) or ||
如果要在if-子句中合并条件,
if
可以将它们与&&
(评估为and )或||
合并在一起。 (evaluates as or ). (评估为或 )。
if (cond1 && cond2) // Will only be true if both cond1 and cond2 is true.
if (cond1 || cond2) // Will be true if either of cond1 or cond2 is true.
This code should be sufficient for your solution: 此代码应足以满足您的解决方案:
<?php if(is_page('Home')) { ?>
<!-- You're on page Home -->
<?php } elseif (is_page('home-2') && in_category('projects')) { ?>
<!-- You're on page home-2 in category projects -->
<?php } else { ?>
<!-- You're somewhere else -->
<?php } ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.