jpilantrose
Member
Posted 1 year ago #
Hi all,
I'm using wp_dropdown_categories in my sidebar and want the code to route to the permalink instead of the raw ?cat= variable. Is there an easy way to make the category slug appear as the option value? Or is this something that I need to custom code in php?
My code basically looks like this
<?php wp_dropdown_categories('exclude=1&depth=1&hierarchical=1'); ?>
<script type="text/javascript"><!--
var dropdown = document.getElementById("cat");
function onCatChange() {
var dd=this;
if ( dd.options[dd.selectedIndex].value > 0 ) {
location.href = "<?php echo get_option('home');
?>/?cat="+dd.options[dd.selectedIndex].value;
}
}
dropdown.onchange = onCatChange;
--></script>
Thanks for any help or tutorials you can send me to!
Jeff
jpilantrose
Member
Posted 1 year ago #
Thanks esmi. I've looked at this part of the codex before. This code still generates out options with select values that reflect the cat IDs so when the redirect happens the url is blogurl/?cat=#
I'm trying to figure out if there is a wordpress setting that I'm overlooking that will make the value of the options the category slug, so the redirect will be my permalink instead of the ugly variable url.
jpilantrose
Member
Posted 1 year ago #
I ended up changing line 1444 of wp-includes/classes.php to
$output .= "<option class=\"level-$depth\" value=\"".$category->slug."\"";
Then I adjusted the javascript accordingly. Was this really the only way to do this or was there a simpler way to get this variable changes that I'm overlooking?