Created
June 1, 2012 18:42
-
-
Save wpsmith/2854297 to your computer and use it in GitHub Desktop.
Taxonomy Dropdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Creates HTML markup for taxonomy dropdown | |
* | |
* @param string $taxonomy Registered taxonomy name | |
*/ | |
function we_tax_dropdown( $taxonomy ) { | |
$terms = get_terms( $taxonomy ); | |
$taxonomy = get_taxonomy( $taxonomy ); | |
if ( empty( $terms ) ) | |
return; | |
$current = get_query_var( $taxonomy->name ); | |
echo "<select name='$taxonomy->name' id='$taxonomy->name' class='taxonomy-search postform'>\n\t"; | |
echo '<option value="" ' . selected( $current == '', true, false ) . '>' . __( 'Select ' . $taxonomy->labels->name, CHILD_DOMAIN ) . '</option>'; | |
foreach ( (array) $terms as $term ) | |
echo "\t<option value='{$term->slug}' " . selected( $current, $term->slug, false ) . ">{$term->name} ({$term->count})</option>\n"; | |
echo '</select>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment