Skip to content

Instantly share code, notes, and snippets.

@atsea
Created August 14, 2014 16:00
Show Gist options
  • Save atsea/c5faf13eb0a6fb0cf687 to your computer and use it in GitHub Desktop.
Save atsea/c5faf13eb0a6fb0cf687 to your computer and use it in GitHub Desktop.
WordPress: Extend Nav Walker Class for $terms seach
<?php
/**
* Taxonomy Drop Down with hierarchical view using $terms
* http://wordpress.stackexchange.com/questions/73583/taxonomy-drop-down-with-hierarchical-view-using-terms
*/
// Equipment Category Dropdown, thanks https://gist.github.com/2902509
class Walker_SlugValueCategoryDropdown extends Walker_CategoryDropdown {
function start_el(&$output, $category, $depth, $args) {
$pad = str_repeat('&nbsp;', $depth * 3);
$cat_name = apply_filters('list_cats', $category->name, $category);
$output .= "\t<option class=\"level-$depth\" value=\"".$category->slug."\"";
if ( $category->term_id == $args['selected'] )
$output .= ' selected="selected"';
$output .= '>';
$output .= $pad.$cat_name;
if ( $args['show_count'] )
$output .= '&nbsp;&nbsp;('. $category->count .')';
if (isset ( $args['show_last_update'] ) ) {
$format = 'Y-m-d';
$output .= '&nbsp;&nbsp;' . gmdate($format, $category->last_update_timestamp);
}
$output .= "</option>\n";
}
}
?>
<h2><?php _e('Categories:'); ?></h2>
<form role="search" method="get" id="equipfilter" action="<?php bloginfo('url'); ?>">
<fieldset>
<?php
$dropdown_args = array(
'taxonomy' => 'software_categories',
'name' => 'Categories',
'show_option_none' => 'Choose category',
'show_count' => 1,
'orderby' => 'name',
'hierarchical' => true,
'echo' => 1,
'walker' => new Walker_SlugValueCategoryDropdown);
wp_dropdown_categories( $dropdown_args );
?>
</fieldset>
<input type="submit" id="filtersubmit" value="Search" />
</form>
<h2><?php _e('Platform:'); ?></h2>
<form role="search" method="get" id="equipfilter" action="<?php bloginfo('url'); ?>">
<fieldset>
<?php
$dropdown_args = array(
'taxonomy' => 'software_platform',
'name' => 'Platform',
'show_option_none' => 'Choose platform',
'show_count' => 1,
'orderby' => 'name',
'hierarchical' => true,
'echo' => 1,
'walker' => new Walker_SlugValueCategoryDropdown);
wp_dropdown_categories( $dropdown_args );
?>
</fieldset>
<input type="submit" id="filtersubmit" value="Search" />
</form>
<h2><?php _e('Audience:'); ?></h2>
<form role="search" method="get" id="equipfilter" action="<?php bloginfo('url'); ?>">
<fieldset>
<?php
$dropdown_args = array(
'taxonomy' => 'software_audience',
'name' => 'Categories',
'show_option_none' => 'Choose audience',
'show_count' => 1,
'orderby' => 'name',
'hierarchical' => true,
'echo' => 1,
'walker' => new Walker_SlugValueCategoryDropdown);
wp_dropdown_categories( $dropdown_args );
?>
</fieldset>
<input type="submit" id="filtersubmit" value="Search" />
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment