WordPress.org

Make WordPress Core

Ticket #15258: multiple-category-dropdowns.patch

File multiple-category-dropdowns.patch, 1.4 KB (added by froman118, 8 years ago)

patch to add unique identifier for dropdowns on Category widget

  • default-widgets.php

     
    438438                $cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h);
    439439
    440440                if ( $d ) {
     441                        $unique_cat_id = 'dropdown_'.str_replace('-', '_', $args['widget_id']);
     442                        $cat_args['id'] = $unique_cat_id;
    441443                        $cat_args['show_option_none'] = __('Select Category');
    442444                        wp_dropdown_categories(apply_filters('widget_categories_dropdown_args', $cat_args));
    443445?>
    444446
    445447<script type='text/javascript'>
    446448/* <![CDATA[ */
    447         var dropdown = document.getElementById("cat");
    448         function onCatChange() {
    449                 if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
    450                         location.href = "<?php echo home_url(); ?>/?cat="+dropdown.options[dropdown.selectedIndex].value;
     449        var <?php echo $unique_cat_id; ?> = document.getElementById("<?php echo $unique_cat_id; ?>");
     450        function onCatChange_<?php echo $unique_cat_id; ?>() {
     451                if ( <?php echo $unique_cat_id; ?>.options[<?php echo $unique_cat_id; ?>.selectedIndex].value > 0 ) {
     452                        location.href = "<?php echo get_option('home'); ?>/?cat="+<?php echo $unique_cat_id; ?>.options[<?php echo $unique_cat_id; ?>.selectedIndex].value;
    451453                }
    452454        }
    453         dropdown.onchange = onCatChange;
     455        <?php echo $unique_cat_id; ?>.onchange = onCatChange_<?php echo $unique_cat_id; ?>;
    454456/* ]]> */
    455457</script>
    456458