Make WordPress Core

Changeset 5319


Ignore:
Timestamp:
04/26/2007 05:17:30 PM (17 years ago)
Author:
ryan
Message:

Add dropdown option to archives and categories widgets. Props Joseph Scott. fixes #4194 for 2.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/widgets.php

    r5317 r5319  
    335335    $options = get_option('widget_archives');
    336336    $c = $options['count'] ? '1' : '0';
     337    $d = $options['dropdown'] ? '1' : '0';
    337338    $title = empty($options['title']) ? __('Archives') : $options['title'];
    338 ?>
    339         <?php echo $before_widget; ?>
    340             <?php echo $before_title . $title . $after_title; ?>
    341             <ul>
    342             <?php wp_get_archives("type=monthly&show_post_count=$c"); ?>
    343             </ul>
    344         <?php echo $after_widget; ?>
    345 <?php
     339
     340    echo $before_widget;
     341    echo $before_title . $title . $after_title;
     342
     343    if($d) {
     344?>
     345        <select name="archive-dropdown" onChange='document.location.href=this.options[this.selectedIndex].value;'> <?php wp_get_archives('type=monthly&format=option'); ?> </select>
     346<?php   
     347    } else {
     348?>
     349        <ul>
     350        <?php wp_get_archives("type=monthly&show_post_count=$c"); ?>
     351        </ul>
     352<?php
     353    }
     354
     355    echo $after_widget;
    346356}
    347357
     
    350360    if ( $_POST["archives-submit"] ) {
    351361        $newoptions['count'] = isset($_POST['archives-count']);
     362        $newoptions['dropdown'] = isset($_POST['archives-dropdown']);
    352363        $newoptions['title'] = strip_tags(stripslashes($_POST["archives-title"]));
    353364    }
     
    357368    }
    358369    $count = $options['count'] ? 'checked="checked"' : '';
     370    $dropdown = $options['dropdown'] ? 'checked="checked"' : '';
    359371    $title = htmlspecialchars($options['title'], ENT_QUOTES);
    360372?>
    361373            <p><label for="archives-title"><?php _e('Title:'); ?> <input style="width: 250px;" id="archives-title" name="archives-title" type="text" value="<?php echo $title; ?>" /></label></p>
    362374            <p style="text-align:right;margin-right:40px;"><label for="archives-count">Show post counts <input class="checkbox" type="checkbox" <?php echo $count; ?> id="archives-count" name="archives-count" /></label></p>
     375            <p style="text-align:right;margin-right:40px;"><label for="archives-dropdown">Use drop down format <input class="checkbox" type="checkbox" <?php echo $dropdown; ?> id="archives-dropdown" name="archives-dropdown" /></label></p>
    363376            <input type="hidden" id="archives-submit" name="archives-submit" value="1" />
    364377<?php
     
    516529    $c = $options['count'] ? '1' : '0';
    517530    $h = $options['hierarchical'] ? '1' : '0';
     531    $d = $options['dropdown'] ? '1' : '0';
    518532    $title = empty($options['title']) ? __('Categories') : $options['title'];
    519 ?>
    520         <?php echo $before_widget; ?>
    521             <?php echo $before_title . $title . $after_title; ?>
    522             <ul>
    523             <?php wp_list_cats("sort_column=name&optioncount=$c&hierarchical=$h"); ?>
    524             </ul>
    525         <?php echo $after_widget; ?>
    526 <?php
     533
     534    echo $before_widget;
     535    echo $before_title . $title . $after_title;
     536
     537    $cat_args = "sort_column=name&optioncount={$c}&hierarchical={$h}";
     538
     539    if($d) {
     540        wp_dropdown_categories($cat_args);
     541?>
     542
     543<script lang='javascript'><!--
     544    var dropdown = document.getElementById("cat");
     545    function onCatChange() {
     546        location.href = "?cat="+dropdown.options[dropdown.selectedIndex].value;
     547    }
     548    dropdown.onchange = onCatChange;
     549--></script>
     550
     551<?php
     552    } else {
     553?>
     554        <ul>
     555        <?php wp_list_cats($cat_args); ?>
     556        </ul>
     557<?php
     558    }
     559
     560    echo $after_widget;
    527561}
    528562
     
    532566        $newoptions['count'] = isset($_POST['categories-count']);
    533567        $newoptions['hierarchical'] = isset($_POST['categories-hierarchical']);
     568        $newoptions['dropdown'] = isset($_POST['categories-dropdown']);
    534569        $newoptions['title'] = strip_tags(stripslashes($_POST['categories-title']));
    535570    }
     
    540575    $count = $options['count'] ? 'checked="checked"' : '';
    541576    $hierarchical = $options['hierarchical'] ? 'checked="checked"' : '';
     577    $dropdown = $options['dropdown'] ? 'checked="checked"' : '';
    542578    $title = wp_specialchars($options['title']);
    543579?>
     
    545581            <p style="text-align:right;margin-right:40px;"><label for="categories-count"><?php _e('Show post counts'); ?> <input class="checkbox" type="checkbox" <?php echo $count; ?> id="categories-count" name="categories-count" /></label></p>
    546582            <p style="text-align:right;margin-right:40px;"><label for="categories-hierarchical" style="text-align:right;"><?php _e('Show hierarchy'); ?> <input class="checkbox" type="checkbox" <?php echo $hierarchical; ?> id="categories-hierarchical" name="categories-hierarchical" /></label></p>
     583            <p style="text-align:right;margin-right:40px;"><label for="categories-dropdown" style="text-align:right;"><?php _e('Use drop down format'); ?> <input class="checkbox" type="checkbox" <?php echo $dropdown; ?> id="categories-dropdown" name="categories-dropdown" /></label></p>
    547584            <input type="hidden" id="categories-submit" name="categories-submit" value="1" />
    548585<?php
Note: See TracChangeset for help on using the changeset viewer.