Adding a class to tag li's
-
Hey Hey,
I was just wondering if anyone came across this. I’ve searched online, but couldn’t find the right information I am looking for.
I am using the jQuery Quicksand plug in to re-order my thumbnails of posts. Similar to http://razorjack.net/quicksand/. This uses classes to identify which post’s are associated with a specific tag.
What I’m trying to do is list the tags that are associated with the all the posts. (Only have 3-5) While listing them I want to add a class (for example “class=”single-tag””)
Then while I’m going through the WP loop I want to add a class of any tags associated with that individual post to the post div that holds the entire content of the post.
Any ideas?
Cheers,
Simon
-
part 1:
if the tag list is done with ‘wp_tag_cloud()’ (as in the tag cloud widget), then this might work by adding a filter function to functions.php of the theme:add_filter ( 'wp_tag_cloud', 'tag_cloud_slug_css_class' ); function tag_cloud_slug_css_class( $return ) { $all_tags = get_terms('post_tag'); if($all_tags) { foreach ($all_tags as $pt) { $tag = $pt->term_id; if(preg_match("#-link-" . $tag . "' #", $return)) { $return = str_replace("tag-link-" . $tag . "' ", "tag-" . $pt->slug . " tag-link-" . $tag . "'", $return); } } } return $return; }this should give each tag link in the list an extra css class
.tag-term-slugpart 2:
post_class()does this automatically to the post div (if used):
http://codex.ww.wp.xz.cn/Template_Tags/post_classit also adds css classes such as
.tag-term-slug
The topic ‘Adding a class to tag li's’ is closed to new replies.