如果不是类别Wordpress-具有多个类别

问题描述 投票:0回答:3

我的页面上有以下代码:

<p class="postmetadata">Category: <?php foreach((get_the_category()) as $cat) {
if (!($cat->cat_ID=='12')) echo '<a href="' . get_bloginfo('url') . '/category/' . $cat->category_nicename . '/">'. $cat->cat_name . '</a>' . ', ';
} ?></p>

很明显,只要猫不是12,它将显示类别名称作为链接。

如果我想包括多个类别,例如

if (!($cat->cat_ID=='12 or 13 or 14'))

我将如何做?

谢谢dvent

wordpress categories
3个回答
0
投票

“ ||”表示“或”,因此类似这样的方法应该起作用:

if ( !($cat->cat_ID=='12') || !($cat->cat_ID=='13') || !($cat->cat_ID=='14') )

0
投票
// Place the list of categories to test inside an array
$categories_list=array(12, 24, 32);
// Then test to see if your category is in this list
if (in_array($cat, $categories_list)) {
  // do something 
}
else 
{
  // do something else
}

0
投票

尝试

if (!is_category(array('12','13','14')))
© www.soinside.com 2019 - 2024. All rights reserved.