"Show all posts" option in category dropdown list link doesnt work
-
I have a dropdown list showing categories for my blog. the “Show All Posts” option shows up, but when selected doesnt go anywhere, the link is just broken. When I select a category the links work fine, only the “Show all posts” link is broken. anyone have any idea how to fix?
<span class="custom-dropdown custom-dropdown--white"> <?php $args = array( 'show_option_none' => 'Select category', 'show_option_all' => 'All Posts' ); ?> <?php wp_dropdown_categories($args); ?> </span> <script type="text/javascript"> <!-- var dropdown = document.getElementById("cat"); function onCatChange() { if ( dropdown.options[dropdown.selectedIndex].value > 0 ) { location.href = "<?php echo esc_url( home_url( '/' ) ); ?>?cat="+dropdown.options[dropdown.selectedIndex].value; } } dropdown.onchange = onCatChange; --> </script>I tried this:
<script type="text/javascript"> <!-- var dropdown = document.getElementById("cat"); function onCatChange() { if ( dropdown.options[dropdown.selectedIndex].value > 0 ) { location.href = "<?php echo esc_url( home_url( '/' ) ); ?>?cat="+dropdown.options[dropdown.selectedIndex].value; } elseif( dropdown.options[dropdown.selectedIndex].value == 0 ){ location.href = "<?php echo esc_url( home_url( '/' ) ); ?>blog"; } } dropdown.onchange = onCatChange; --> </script>but that code breaks all the category links
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘"Show all posts" option in category dropdown list link doesnt work’ is closed to new replies.