当我使用自定义模板标签输出单个帖子标签时:
<?php
echo get_the_tag_list('<p class="text-muted"><i class="fa fa-tags"></i> ',', ','</p>');
?>
如何从标签列表中排除已定义的标签名称?
好吧,没有过滤器可以删除其中的术语get_the_tag_list
但在内部它要求get_the_terms
所以你可以在那里添加过滤器。
考虑这个例子:-
add_filter('get_the_terms', 'exclude_terms');
echo get_the_tag_list('<p class="text-muted"><i class="fa fa-tags">',', ','</i></p>');
remove_filter('get_the_terms', 'exclude_terms');
添加过滤器get_the_terms
并在回显列表后将其删除。因为它可能会在页面上被调用多次。
并在回调函数中通过 ID 或 slugs 删除术语
function exclude_terms($terms) {
$exclude_terms = array(9,11); //put term ids here to remove!
if (!empty($terms) && is_array($terms)) {
foreach ($terms as $key => $term) {
if (in_array($term->term_id, $exclude_terms)) {
unset($terms[$key]);
}
}
}
return $terms;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)