List all taxonomy terms and highlight those associated with the current post
-
Am wondering if it is possible to list all terms of a taxonomy type, and add a highlight class to those terms which are associated with the current post/custom post type? Perhaps something similar to this solution for achieving the same thing for wp_list_categories:
class KHUC { function wp_list_categories ($text) { global $post; if (is_singular()) { $categories = wp_get_post_categories($post->ID); foreach ($categories as $category_id) { $category = get_category($category_id); $category_parent = get_category($category->category_parent); $text = preg_replace( "/class=\"(.*)\"><a ([^<>]*)>$category->name<\/a>/", ' class="$1 used-cat"><a $2>' . $category->name . '</a>', $text); $text = preg_replace( "/class=\"(.*)\"><a ([^<>]*)>$category_parent->name<\/a>/", ' class="$1 used-cat-parent"><a $2>' . $category_parent->name . '</a>', $text); } } return $text; } }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘List all taxonomy terms and highlight those associated with the current post’ is closed to new replies.