Make WordPress Core

Changeset 21935


Ignore:
Timestamp:
09/21/2012 10:05:54 AM (12 years ago)
Author:
westi
Message:

Widgets: Add support for display the post date in the Recent Posts widget. Fixes #21064 props lancewillett and SergeyBiryukov.

File:
1 edited

Legend:

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

    r21867 r21935  
    562562        if ( empty( $instance['number'] ) || ! $number = absint( $instance['number'] ) )
    563563            $number = 10;
     564        $show_date = isset( $instance['show_date'] ) ? $instance['show_date'] : false;
    564565
    565566        $r = new WP_Query( apply_filters( 'widget_posts_args', array( 'posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true ) ) );
     
    569570        <?php if ( $title ) echo $before_title . $title . $after_title; ?>
    570571        <ul>
    571         <?php  while ($r->have_posts()) : $r->the_post(); ?>
    572         <li><a href="<?php the_permalink() ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?></a></li>
     572        <?php while ( $r->have_posts() ) : $r->the_post(); ?>
     573            <li>
     574                <a href="<?php the_permalink() ?>" title="<?php echo esc_attr( get_the_title() ? get_the_title() : get_the_ID() ); ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?></a>
     575            <?php if ( $show_date ) : ?>
     576                <span class="post-date"><?php echo get_the_date(); ?></span>
     577            <?php endif; ?>
     578            </li>
    573579        <?php endwhile; ?>
    574580        </ul>
     
    588594        $instance['title'] = strip_tags($new_instance['title']);
    589595        $instance['number'] = (int) $new_instance['number'];
     596        $instance['show_date'] = (bool) $new_instance['show_date'];
    590597        $this->flush_widget_cache();
    591598
     
    602609
    603610    function form( $instance ) {
    604         $title = isset($instance['title']) ? esc_attr($instance['title']) : '';
    605         $number = isset($instance['number']) ? absint($instance['number']) : 5;
    606 ?>
    607         <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
    608         <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></p>
    609 
    610         <p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number of posts to show:'); ?></label>
    611         <input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number; ?>" size="3" /></p>
     611        $title     = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
     612        $number    = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
     613        $show_date = isset( $instance['show_date'] ) ? (bool) $instance['show_date'] : false;
     614?>
     615        <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
     616        <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" /></p>
     617
     618        <p><label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of posts to show:' ); ?></label>
     619        <input id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>" type="text" value="<?php echo $number; ?>" size="3" /></p>
     620
     621        <p><input class="checkbox" type="checkbox" <?php checked( $show_date ); ?> id="<?php echo $this->get_field_id( 'show_date' ); ?>" name="<?php echo $this->get_field_name( 'show_date' ); ?>" />
     622        <label for="<?php echo $this->get_field_id( 'show_date' ); ?>"><?php _e( 'Display post date?' ); ?></p>
    612623<?php
    613624    }
Note: See TracChangeset for help on using the changeset viewer.