首次添加get_the_categories
之前筛选the_category(\' , \')
然后将其移除。因此,它不会影响其他地方的类别。
add_filter( \'get_the_categories\', \'remove_selected_categories\' );
the_category(\' , \');
remove_filter( \'get_the_categories\', \'remove_selected_categories\' );
在回调函数中,检查要删除的类别,然后删除它们!
function remove_selected_categories( $categories ) {
$categories_to_remove = array(
\'years\',
\'genere\'
); //Place the slug for categories
foreach ($categories as $index => $single_cat) {
if (in_array($single_cat->slug, $categories_to_remove)) {
unset($categories[$index]);
}
}
return $categories;
}
检查文档
get_the_categories 滤器