我似乎在任何地方都找不到这个问题的答案,所以我想知道是否有人可以帮助我?
如何组合is_page和in_category子句?
目前,home-2 ( slug)似乎不想工作。
<?php if(is_page( 'Home' )) { ?>
<?php } elseif (is_page('home-2')) { ?>
<?php } elseif (in_category('projects')) { ?>
<?php } else { ?>
<?php } ?>谢谢。
发布于 2018-11-05 19:24:29
条件'&&‘是' and’,'||‘是'OR’。使用this和组合多个子句。
if(is_page('home-2') && in_category('projects')){
OR
if(is_page('home-2') || in_category('projects')){
//Your Statement here
}发布于 2018-11-05 19:28:09
如果要在if-clause中组合条件,可以使用&& (计算结果为and)或|| (计算结果为或)将它们连接起来。
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. 以下代码应该足以满足您的解决方案:
<?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 } ?>https://stackoverflow.com/questions/53153242
复制相似问题