Make WordPress Core


Ignore:
Timestamp:
05/18/2007 02:29:11 AM (17 years ago)
Author:
rob1n
Message:

Texturize and autop the text widgets, and allow pages to be sorted by a specified field. Props Denis de Bernardy. see #4259

File:
1 edited

Legend:

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

    r5485 r5486  
    327327/* Default Widgets */
    328328
    329 function wp_widget_pages($args) {
    330     extract($args);
    331     $options = get_option('widget_pages');
    332     $title = empty($options['title']) ? __('Pages') : $options['title'];
    333     echo $before_widget . $before_title . $title . $after_title . "<ul>\n";
    334     wp_list_pages("title_li=");
    335     echo "</ul>\n" . $after_widget;
     329function wp_widget_pages( $args ) {
     330    extract( $args );
     331    $options = get_option( 'widget_pages' );
     332   
     333    $title = empty( $options['title'] ) ? __( 'Pages' ) : $options['title'];
     334    $sortby = empty( $options['sortby'] ) ? 'menu_order' : $options['sortby'];
     335   
     336    if ( $sortby == 'menu_order' ) {
     337        $sortby = 'menu_order, post_title';
     338    }
     339   
     340    $out = wp_list_pages( 'title_li=&echo=0&sort_column=' . $sortby );
     341   
     342    if ( !empty( $out ) ) {
     343?>
     344    <?php echo $before_widget; ?>
     345        <?php echo $before_title . $title . $after_title; ?>
     346        <ul>
     347            <?php echo $out; ?>
     348        </ul>
     349    <?php echo $after_widget; ?>
     350<?php
     351    }
    336352}
    337353
    338354function wp_widget_pages_control() {
    339355    $options = $newoptions = get_option('widget_pages');
    340     if ( $_POST["pages-submit"] ) {
    341         $newoptions['title'] = strip_tags(stripslashes($_POST["pages-title"]));
     356    if ( $_POST['pages-submit'] ) {
     357        $newoptions['title'] = strip_tags(stripslashes($_POST['pages-title']));
     358       
     359        $sortby = stripslashes( $_POST['pages-sortby'] );
     360       
     361        if ( in_array( $sortby, array( 'post_title', 'menu_order', 'ID' ) ) ) {
     362            $newoptions['sortby'] = $sortby;
     363        } else {
     364            $newoptions['sortby'] = 'menu_order';
     365        }
    342366    }
    343367    if ( $options != $newoptions ) {
     
    348372?>
    349373            <p><label for="pages-title"><?php _e('Title:'); ?> <input style="width: 250px;" id="pages-title" name="pages-title" type="text" value="<?php echo $title; ?>" /></label></p>
     374            <p><label for="pages-sortby"><?php _e( 'Sort by:' ); ?>
     375                <select name="pages-sortby" id="pages-sortby">
     376                    <option value="post_title"><?php _e('Page title'); ?></option>
     377                    <option value="menu_order"><?php _e('Menu order'); ?></option>
     378                    <option value="ID"><?php _e( 'Page ID' ); ?></option>
     379                </select></label></p>
    350380            <input type="hidden" id="pages-submit" name="pages-submit" value="1" />
    351381<?php
     
    496526    if ( empty($title) )
    497527        $title = '&nbsp;';
    498     $text = $options[$number]['text'];
     528    $text = apply_filters( 'the_content', $options[$number]['text'] );
    499529?>
    500530        <?php echo $before_widget; ?>
    501             <?php $title ? print($before_title . $title . $after_title) : null; ?>
     531            <?php !empty( $title ) ? print($before_title . $title . $after_title) : null; ?>
    502532            <div class="textwidget"><?php echo $text; ?></div>
    503533        <?php echo $after_widget; ?>
     
    522552    $text = attribute_escape($options[$number]['text']);
    523553?>
    524             <input style="width: 450px;" id="text-title-<?php echo "$number"; ?>" name="text-title-<?php echo "$number"; ?>" type="text" value="<?php echo $title; ?>" />
    525             <textarea style="width: 450px; height: 280px;" id="text-text-<?php echo "$number"; ?>" name="text-text-<?php echo "$number"; ?>"><?php echo $text; ?></textarea>
     554            <input style="width: 450px;" id="text-title-<?php echo $number; ?>" name="text-title-<?php echo $number; ?>" type="text" value="<?php echo $title; ?>" />
     555            <textarea style="width: 450px; height: 280px;" id="text-text-<?php echo $number; ?>" name="text-text-<?php echo $number; ?>"><?php echo $text; ?></textarea>
    526556            <input type="hidden" id="text-submit-<?php echo "$number"; ?>" name="text-submit-<?php echo "$number"; ?>" value="1" />
    527557<?php
Note: See TracChangeset for help on using the changeset viewer.