get_the_tags
将返回一个标记对象,因此您必须创建一个post标记数组,然后查看$tag->name
位于post tags数组中。
$tags = get_tags();
$post_tags = get_the_tags($post->ID);
/* Just make an array so you can use in_array function later on */
$post_tag_array = array();
foreach( $post_tags as $post_tag ){
array_push($post_tag_array,$post_tag->name);
}
if ($tags) {
foreach ($tags as $tag) {
/* Then change to search this array for the $tag->name */
if( (is_tag($tag)) || ( in_array($tag->name, $post_tag_array )) ){
echo \'<a href="\'.get_tag_link($tag->term_id).\'" title="\'.$tag->name.\'" class="currenttag">\'.$tag->name.\'</a> \';
} else {
echo \'<a href="\'.get_tag_link($tag->term_id).\'" title="\'.$tag->name.\'"">\'.$tag->name.\'</a> \';
}
}
}
希望这有帮助