The default WordPress categories widget does not allow excluding named categories.
I’ve created a plugin which creates adds a Customized category widget to the “Available Widgets” listing which gives me some control over the items I want to exclude. Code is 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 categories widget (ie, the word “categories” appears as a bullet in my widget, but as an h4 level heading element in the default categories widget. I want the same structure to be applied to my custom widget as the default categories widget has.
I’d also like to give the user the options to specify the title of the categories listing (just as they can do in the default categories widget).
btw, I’m using id 1 which is the default “uncategorized” category and assigning items to that category that I don’t want to appear in the listing.
Any help much appreciated! 🙂
The code for the categories widget is in
wp-includes/default_widgets.php
. Just copy theWP_Widget_Categories
class, rename it and add your extra arguments to thewp_list_categories
call.Alternatively you can modify the arguments for the
wp_list_categories
call in the widget using thewidget_categories_args
filter, although that will apply to all instances of the widget.