I have this code to populate a custom dropdown menu of my WP categories. Now this is all working fine, but i'd like the current category to be selected in the dropdown. How can i do this?
<select name="page-dropdown"
onchange='document.location.href=this.options[this.selectedIndex].value;'>
<?php
hierarchical_category_tree( 0 ); // the function call; 0 for all categories; or cat ID
function hierarchical_category_tree( $cat ) {
// wpse-41548 // alchymyth // a hierarchical list of all categories //
$next = get_categories('hide_empty=false&orderby=name&order=ASC&parent=' . $cat);
if( $next ) :
foreach( $next as $cat ) :
echo '<option value="' . get_category_link( $cat->term_id ) . '">' . $cat->name . '</option>';
hierarchical_category_tree( $cat->term_id );
endforeach;
endif;
echo "\n";
}
?> </select>
Any help is greatly appreciated! Thank you.