How to hide sub categories in sidebar ?

Discussion in 'WordPress' started by links4rank, May 26, 2010.

  1. #1
    Hi, there,

    Anyone can tell me how to hide subcategories in sidebar ?

    Thanks in advance!
     
    links4rank, May 26, 2010 IP
  2. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #2
    Add this code in the file functions.php of the theme directory:

    
    <?php
    function exclude_widget_subcategories($args){
      $all_categories = get_all_category_ids();
    
      $exclude_categories = array();
    
      foreach($all_categories as $category_id){
        $category = get_category($category_id);
    
        if($category->parent!=0){
            $exclude_categories[] = $category_id;
        }
      }
      $exclude = implode(",",$exclude_categories); // The IDs of the excluding categories
      $args["exclude"] = $exclude;
      return $args;
    }
    add_filter("widget_categories_args","exclude_widget_subcategories");
    ?>
    
    Code (markup):
    This is modified code of the post http://rubensargsyan.com/exclude-categories-from-the-default-widget-categories/
     
    s_ruben, May 26, 2010 IP
  3. bhuthecoder

    bhuthecoder Member

    Messages:
    245
    Likes Received:
    11
    Best Answers:
    1
    Trophy Points:
    43
    #3
    use this plugin to hide subcategories
    Enhanced Category widget
    http://wordpress.org/extend/plugins/my-category-order/
    Code (markup):
     
    bhuthecoder, May 27, 2010 IP
  4. juhasan

    juhasan Well-Known Member

    Messages:
    389
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    125
    #4
    juhasan, May 27, 2010 IP
  5. links4rank

    links4rank Well-Known Member

    Messages:
    311
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #5
    Thank you guys !
     
    links4rank, May 27, 2010 IP