我有一个名为“特色”的分类,但我不希望这个分类标签显示在单个帖子页面的底部。我确实想显示其他类别标记。如何隐藏此类别的标记?
在单个帖子页面上隐藏特定类别标签
3 个回复
SO网友:Antti Koskinen
对于特定的帖子类别,您可以使用get_the_categories 筛选挂钩,以删除找到的特定类别(术语)。
function filter_get_the_category( $categories, $post_id ) {
// loop post categories
foreach ($categories as $index => $category) {
// check for certain category, you could also check for $term->slug or $term->term_id
if ( \'Featured\' === $category->name ) {
// remove it from the array
unset( $categories[$index] );
}
}
return $categories;
}
add_filter( \'get_the_categories\', \'filter_get_the_category\', 10, 2 );
要筛选任何分类术语,可以使用get_the_terms 钩function filter_get_the_terms( $terms, $post_id, $taxonomy ) {
// target certain taxonomy
if ( \'category\' === $taxonomy && ! is_wp_error( $terms ) ) {
// loop found terms
foreach ($terms as $index => $term) {
// check for certain term, you could also check for $term->slug or $term->term_id
if ( \'Featured\' === $term->name ) {
// remove it from the array
unset( $terms[$index] );
}
}
}
return $terms;
}
add_filter( \'get_the_terms\', \'filter_get_the_terms\', 10, 3 );
SO网友:MrFox
我决定采用这个简单的解决方案
if ( in_category(\'featured\') ) {
}else{
entry_meta();
}
SO网友:David Lee
我试图遵循上面的代码,但没有成功。访问与CSR事件类别相关的帖子时,如何隐藏公司新闻类别?请参见下面的页面链接:https://www.mi-eq.com/blood-donation-compaign/