How to diffentiate categories and sub-categories on a filter dropdown
-
Hi, I have a site with a Custom Post Type for wholesale products. When you enter in a product, you can check categories and subcategories (like Handbag, Jewelry, etc. And below handbag you can check Tote Bag or Beach Bag).
I have this code that allows the user to filter through the list.
<?php // check if we got posts to display: if (have_posts()) : $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array("post_type" => "wholesale", "orderby" => "date", "posts_per_page" => "20", "paged" => $paged ); global $sortby; $sortby = $_GET['sortby']; if ($sortby == "title") { $args["orderby"] = "title"; } global $genre_filter; $genre_filter = $_GET['genre']; if ($genre_filter) { $args['tax_query'] = array(array("taxonomy" => "wholesale_cats", "terms" => $genre_filter, "field" => "slug", "hierarchical" => "1" )); } query_posts($args); ?> <div class="wholesale-filter"> <span>FILTER:</span> <?php global $genre_filter, $sortby; ?> <a class="genre_all" href="?sortby=<?php echo $sortby; ?>">ALL</a> <a class="sort_title" href="?sortby=title&genre=<?php echo $genre_filter; ?>">A-Z</a> <script language="JavaScript" type="text/JavaScript"> <!-- function MM_jumpMenu(targ,selObj,restore){ //v3.0 eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'"); if (restore) selObj.selectedIndex=0; } //--> </script> <form name="form1" id="form1" class="wholesale-dropdown"> <select name="menu1" onchange="MM_jumpMenu('parent',this,0)"> <option value="Make a selection">--- make a selection ---</option> <option value="?sortby=<?php echo $sortby; ?>">--- All ---</option> <?php $genres = get_terms("wholesale_cats"); if ($genres) { foreach ($genres as $genre) { // print_r($genre); echo '<option value="?view_mode='.$_GET['view_mode'].'&genre='. $genre->slug .'&sortby='.$sortby.'">' . $genre->name . '</option>'; } } ?> </select> </form>
This works great, but shows all categories and sub categories all in one drop down. How do I get it so sub categories have an indent in their visual display?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘How to diffentiate categories and sub-categories on a filter dropdown’ is closed to new replies.