• Mike

    (@shakingpaper)


    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)
  • Sure would be nice to know!

    Moderator bcworkz

    (@bcworkz)

    I think it’s possible, but not that easy. I don’t know of any WP functions that really help. You’ll have to figure out how the taxonomy tables work and create SQL queries for use in $wpdb methods to get the info you need. Then it’s just a matter of cycling through the returned arrays and formatting the output accordingly.

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.