View Single Post
Old 10-09-2011, 06:48 PM  
fris
Too lazy to set a custom title
 
fris's Avatar
 
Industry Role:
Join Date: Aug 2002
Posts: 55,297
Quote:
Originally Posted by garce View Post
I never use widgets - I can't stand the things - but I HAVE to use widgets for this project.

Using the default Categories widget, how do I exclude certain categories from being listed in the sidebar?

Update and Edit:

Ok, that was fucking simple - in spite of the massive amount of incorrect information I received from Google and its three year old (yet extremely relevant - rofl) results...

To exclude a category from the default sidebar widget, open default-widgets.php and add:

Code:
$ex = 'whateverIDthecatis,anothercatID';
under

Code:
class WP_Widget_Categories extends WP_Widget
The source told me what to do right here:

Code:
$cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h, 'exclude' => $ex );
I should have just opened default-widgets.php and read the source before searching useless Google.

So, ignore this - unless I've missed something important - then I would truly appreciate your input.

Posting this only because someone may search for this information... I doubt it - no-one searches for shit - but hey!
never edit the core files ;)

you want to hook into the filter widget_categories_args

Code:
add_filter('widget_categories_args', 'my_cats_filter');

function my_cats_filter( $args ) {
    $args['exclude'] = 2;
    return $args;
}
2 being the id of the category, if you need more than 1 make it an array of ids.
__________________
Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.


WP Stuff
fris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote