Forums

[resolved] [Widget] Drop Down style menu with specific categories (2 posts)

  1. Ryutso
    Member
    Posted 5 months ago #

    The normal "Catergories" menu drop down box is great, but I can't exclude certain categories from it, like with the "Pages" widget.

    Is there a code or plugin I can add in my sidebar to just display the child categories of a certain parent category?

    My site: http://concrazy.x10.mx/

  2. Ryutso
    Member
    Posted 5 months ago #

    Whoop, solved it myself.

    <select name="event-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'>
     <option value=""><?php echo esc_attr(__('Select Option')); ?></option>
     <?php
      $categories=  get_categories(array('hide_empty' => 0, 'name' => 'category_parent', 'child_of' => 5, 'orderby' => 'name', 'selected' => $category->parent, 'hierarchical' => true, 'show_option_none' => __('Select Option')));
      foreach ($categories as $category) {
      	$option = '<option value="/?cat='.$category->cat_ID.'">';
    	$option .= $category->cat_name;
    	$option .= '</option>';
    	echo $option;
      }
     ?>
    </select>

Reply

You must log in to post.

About this Topic