Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm new for WordPress. I'm using following code,

<div id="cat_list">
    <?php wp_dropdown_categories(array('show_option_all' => 'Categories') ); ?> 
</div>

And my JavaScript is,

<script type="text/javascript">
    var dropdown = document.getElementById("cat");
    function onCatChange() {
        if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
            location.href = "<?php echo get_option('home');
?>/?cat="+dropdown.options[dropdown.selectedIndex].value;
        }
    }
    dropdown.onchange = onCatChange;
</script>

If I select any Category means, that goes to correct page. But my requirement is, Will be go home page when re-select Categories (show_option_all).

Any option is in WordPress? other what to do?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

You can try this

<script type="text/javascript">
    var dropdown = document.getElementById("cat");
    function onCatChange() {
        if ( dropdown.selectedIndex == 0 ) {
            location.href = "<?php echo get_option('home');?>";
        }else if ( dropdown.selectedIndex > 0 ) {
            location.href = "<?php echo get_option('home');?>/?cat="+dropdown.options[dropdown.selectedIndex].value;
        }
    }
    dropdown.onchange = onCatChange;
</script>
share|improve this answer
    
thanks @birgire –  KarSho Mar 14 '13 at 8:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.