Hack WordPress category widget
The default WordPress category widget does not allow excluding named categories.
I created a plugin that adds a Custom Category widget to the Available Widgets list, which gives me some control over the items I want to exclude. Code below ...
<?php
/*
Plugin Name: Custom Categories Widget
Plugin URI: http://mysite.com
Description: Removes the Specified Categories from the Default Categories Listing
Author: Me
Version: 1.0
Author URI: http://mysite.com
*/
function widget_my_categories()
{
wp_list_categories('exclude=1');
}
function my_categories_init()
{
register_sidebar_widget(__('Custom Categories Widget'), 'widget_my_categories');
}
add_action("plugins_loaded", "my_categories_init");
?>
However, I want the generated code to emulate the same look and feel as the default category widget (i.e. the word "categories" appears as a marker in my widget, but as an h4 level heading element in category widgets by default I want the same structure applied to my custom widget as the category widget has by default.
I would also like to give the user the ability to specify a title for the category list (just like they can do in the default widgets).
btw, I'm using id 1, which is the default "no categorization" category and assigns items to that category that I don't want to show in the list.
Any help is greatly appreciated! :)
a source to share
The category widget code is in wp-includes/default_widgets.php
. Just copy the class WP_Widget_Categories
, rename it, and add additional arguments to the call wp_list_categories
.
Alternatively, you can change the arguments to be called wp_list_categories
in the widget_categories_args
widget using a filter , although this applies to all instances of the widget.
a source to share