【发布时间】:2011-09-08 00:19:57
【问题描述】:
我需要为我的帖子分配一些标签(供外部使用),但我不希望它们显示在列出标签的任何地方。谁能给我一个例子来说明如何做到这一点?
【问题讨论】:
我需要为我的帖子分配一些标签(供外部使用),但我不希望它们显示在列出标签的任何地方。谁能给我一个例子来说明如何做到这一点?
【问题讨论】:
这个问题很老了,但我遇到了这个需求,我找到了一个有趣的解决方案,我想分享。
最好对标签应用过滤器,这样您就不必担心模板中显示标签的位置丢失了。
function exclude_tags($tags) {
foreach ($tags as $tag)
switch ($tag->name) {
case 'exclude-this-tag':
case 'exclude-this-tag-too':
break;
default:
$newtags[] = $tag;
}
return $newtags;
}
add_filter( 'get_the_tags', 'exclude_tags');
【讨论】:
the_tags 过滤器。我的主题使用“the_tags”功能。
在模板中使用 get_tags() 代替 the_tags()
$tags = get_tags();
foreach ($tags as $tag)
{
if($tag->name=='the tag i want gone') continue;// do this for every tag you want gone
echo $tag->name.', ';
}
【讨论】: