I´m trying to highlight (using css), the child and parent categories in use in the selected post.
So I´ve found this plugin "Kahi's Highlight Used Categories".
Plugin´s website: http://kahi.cz/wordpress/highlight-used-categories-plugin/
What it does...
It adds a 'used-cat' class and 'used-cat-parent' class to stylize, to the sub-category and main category respectively.
The problem is:
My website (http://www.mpn.p.ht/wp_br2/), has three main categories "Masculino", (means male), "Feminino", (means female), and "Infantil", (means infant).
The sub-categories are the same for all the three main categories.
So, let´s say, we are at the post page with main category "Masculino", and sub-category "Acessórios", (means acessories)...
The plugin, seems to add 'used-cat' to all "Acessórios" (sub-category), found also in "Feminino" , and in "Infantil".
I would like the plugin to add the class 'used-cat', only to the sub-category of the selected post. Not to all sub-categories found with the same name, through the categories list.
Here´s the plugin code:
<?php
/*
Plugin Name: Kahi's Highligh Used Categories
Plugin URI: http://www.kahi.cz/wordpress/highlight-used-categories-plugin
Description: In the list of categories, adds classes <code>used-cat</code> and
<code>used-cat-parents</code> to particular list-items (when browsing a post).
Version: 1.0
Author: Peter Kahoun and Dirk Jaster
Author URI: http://www.kahi.cz/wordpress/
*/
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;
}
}
add_filter('wp_list_categories', array('KHUC','wp_list_categories'));
Does anyone know, what changes in the plugin code should I make, so I get only the sub-category in use to get the 'used-cat' class?