FYI, here is a simple change that does offer this functionality, though I really don’t want to be modifying this plugin’s code since it will cause update problems. But in case someone else has this problem, or the plugin author is reading this and is interested in suggestions, here is an option:
In file top-10.php, line 408, change it from:
$p_in_c = (in_array($cat->cat_ID, $exclude_categories)) ? true : false;
to:
$p_in_c = (in_array($cat->cat_ID, $exclude_categories) || in_array($cat->parent, $exclude_categories)) ? true : false;
Plugin Author
Ajay
(@ajay)
Hi,
If I understand correctly, then this code will exclude the display on a category as well as its parent categories?
Yup, correct. in_array($cat->parent, $exclude_categories)
checks to see if the category’s parent is listed in the exclude_categories array.
This wouldn’t go any higher up the category hierarchy though. For instance, if someone had 3 or more levels of child categories, doing this would only climb up one level.
If you would like to offer the ability to exclude an entire parent category and all of its children, you could look into using the custom post_is_in_descendant_category
function listed in the WP Codex:
http://codex.wordpress.org/Function_Reference/in_category#Testing_if_a_post_is_in_a_descendant_category
And thanks for putting out such a great plugin too!
Plugin Author
Ajay
(@ajay)
You’re welcome and thanks for the code. This will ofcourse not be the default feature since that would not work for every users requirements.
But, I can add this as an optional feature for all users.
Thanks! If at all possible, I would love to see this in the next release 😉
In any case, I’ll mark this topic as resolved.
Plugin Author
Ajay
(@ajay)
Will put this on the list to add.
I don’t know if this is what i was needing or not but i wanted a way to filter the top posts by category, like show Top Posts overall but not from the whole blog but for certain category, this filter could be added on the widget as a drop-down menu.
If this isn’t it, then consider for next updates maybe.
Cheers.