GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   How to exclude a category from the default WP Categories widget? (https://gfy.com/showthread.php?t=1041133)

garce 10-09-2011 12:31 PM

How to exclude a category from the default WP Categories widget?
 
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!

fris 10-09-2011 06:48 PM

Quote:

Originally Posted by garce (Post 18479694)
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.


All times are GMT -7. The time now is 03:57 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123