Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'd like to add code to my functions.php to intercept all calls to wp_list_categories() AND the_category() so that it excludes "uncategorized" and any children of "uncategorized" (OR cat_id 1). I'd also like to limit the number of words returned in the "title" attribute of each list item anchor. Currently the default is to set $cat_args['use_desc_for_title'] = 1; but It does not appear it's possible to insert that into the exclusions filter below.

I'm using the code below which effectively removes the unwanted categories from the lists that use wp_list_categories, however, it does not remove them from lists derived from the_category...

function my_list_terms_exclusions($exclusions,$args) {
  $children = implode(',',get_term_children(1,'category'));
  $children = (empty($children) ? '' : ",$children");
  return $exclusions . " AND (t.term_id NOT IN (1{$children}))";
}
add_filter('list_terms_exclusions', 'my_list_terms_exclusions', 10, 2);?>
share|improve this question
1  
Why not just get rid of uncategorized ? Make some other category default one, then you can delete uncategorized. Much less hassle. –  Rarst Jan 11 '11 at 13:30
add comment

1 Answer

up vote 1 down vote accepted

I was finally able to figure this one out... Although I have to set the filter directly on the widget_categories_args method, so it does take two filter statements to do it.

function my_categories_filter($cat_args){
    $cat_args['title_li'] = '';
    $cat_args['exclude_tree'] = 1;
    $cat_args['exclude'] = 1;
    $cat_args['use_desc_for_title'] = 0;
    return $cat_args;
}

add_filter('widget_categories_args', 'my_categories_filter', 10, 2);
share|improve this answer
    
@philip: you would add each one to the exclude list (its an array) –  Scott B Mar 12 '11 at 20:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.