Hacking the WordPress Category Widget
Posted
by Scott B
on Stack Overflow
See other posts from Stack Overflow
or by Scott B
Published on 2010-04-21T21:10:32Z
Indexed on
2010/04/21
21:13 UTC
Read the original article
Hit count: 158
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! :)
© Stack Overflow or respective owner