我当前用于显示类别的代码是<?php foreach((get_the_category()) as $category) { echo $category->cat_name . \' \';}?>
我想排除名为“home featured”的类别或ID为“65”的类别如何将其添加到上述代码中?
最合适的回答,由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 . \' \';
}
?>