Exclude Specific Categories?

时间:2012-11-04 作者:Joe Bobby

我当前用于显示类别的代码是<?php foreach((get_the_category()) as $category) { echo $category->cat_name . \' \';}?>

我想排除名为“home featured”的类别或ID为“65”的类别如何将其添加到上述代码中?

1 个回复
最合适的回答,由SO网友:Joseph Leedy 整理而成

您可以这样做:

<?php
$exclude = array( \'home-featured\' );
foreach( get_the_category() as $category ) {
    if ( ! in_array( $category->cat_name, $exclude )
        echo $category->cat_name . \' \';
}
?>

结束