Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter ( 'wp_tag_cloud', 'tag_cloud_current_tag_highlight' ); | |
function tag_cloud_current_tag_highlight( $return ) { | |
$post_tags = array(); | |
if(is_single()) { | |
global $post; | |
$post_tags = get_the_terms($post->ID,'post_tag'); | |
} | |
if(is_tag()) { | |
$tags = explode( '+', get_query_var('tag') ); | |
foreach( $tags as $tag ) { $post_tags[] = get_term_by('slug',$tag,'post_tag'); } | |
} | |
if( $post_tags ) { | |
foreach ($post_tags as $pt) { | |
$tag = $pt->term_id; | |
if(preg_match("#-link-" . $tag . "' #", $return)) { | |
$return = str_replace("link-" . $tag . "' ", "link-" . $tag . " current-tag' ", $return); | |
} | |
} | |
} | |
return $return; | |
} | |
//current-tagというclassが追加される | |
?> |
Screen shot
Note
Description | 現在閲覧中のページに付けられているタグを取得してタグクラウド内のタグのclassを任意のclassを含めたものに置換する |
---|---|
WordPress Ver. | 3.5 |
Via | Tag Cloud Filter to Show Current Tags |