Widgets: Add support for display the post date in the Recent Posts widget. Fixes #21064 props lancewillett and SergeyBiryukov.
git-svn-id: http://core.svn.wordpress.org/trunk@21935 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
5f2946ba42
commit
d8e08eb3c2
|
@ -561,6 +561,7 @@ class WP_Widget_Recent_Posts extends WP_Widget {
|
||||||
$title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts') : $instance['title'], $instance, $this->id_base);
|
$title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts') : $instance['title'], $instance, $this->id_base);
|
||||||
if ( empty( $instance['number'] ) || ! $number = absint( $instance['number'] ) )
|
if ( empty( $instance['number'] ) || ! $number = absint( $instance['number'] ) )
|
||||||
$number = 10;
|
$number = 10;
|
||||||
|
$show_date = isset( $instance['show_date'] ) ? $instance['show_date'] : false;
|
||||||
|
|
||||||
$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 ) ) );
|
$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 ) ) );
|
||||||
if ($r->have_posts()) :
|
if ($r->have_posts()) :
|
||||||
|
@ -568,8 +569,13 @@ class WP_Widget_Recent_Posts extends WP_Widget {
|
||||||
<?php echo $before_widget; ?>
|
<?php echo $before_widget; ?>
|
||||||
<?php if ( $title ) echo $before_title . $title . $after_title; ?>
|
<?php if ( $title ) echo $before_title . $title . $after_title; ?>
|
||||||
<ul>
|
<ul>
|
||||||
<?php while ($r->have_posts()) : $r->the_post(); ?>
|
<?php while ( $r->have_posts() ) : $r->the_post(); ?>
|
||||||
<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>
|
<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>
|
||||||
|
<?php if ( $show_date ) : ?>
|
||||||
|
<span class="post-date"><?php echo get_the_date(); ?></span>
|
||||||
|
<?php endif; ?>
|
||||||
|
</li>
|
||||||
<?php endwhile; ?>
|
<?php endwhile; ?>
|
||||||
</ul>
|
</ul>
|
||||||
<?php echo $after_widget; ?>
|
<?php echo $after_widget; ?>
|
||||||
|
@ -587,6 +593,7 @@ class WP_Widget_Recent_Posts extends WP_Widget {
|
||||||
$instance = $old_instance;
|
$instance = $old_instance;
|
||||||
$instance['title'] = strip_tags($new_instance['title']);
|
$instance['title'] = strip_tags($new_instance['title']);
|
||||||
$instance['number'] = (int) $new_instance['number'];
|
$instance['number'] = (int) $new_instance['number'];
|
||||||
|
$instance['show_date'] = (bool) $new_instance['show_date'];
|
||||||
$this->flush_widget_cache();
|
$this->flush_widget_cache();
|
||||||
|
|
||||||
$alloptions = wp_cache_get( 'alloptions', 'options' );
|
$alloptions = wp_cache_get( 'alloptions', 'options' );
|
||||||
|
@ -601,14 +608,18 @@ class WP_Widget_Recent_Posts extends WP_Widget {
|
||||||
}
|
}
|
||||||
|
|
||||||
function form( $instance ) {
|
function form( $instance ) {
|
||||||
$title = isset($instance['title']) ? esc_attr($instance['title']) : '';
|
$title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
|
||||||
$number = isset($instance['number']) ? absint($instance['number']) : 5;
|
$number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
|
||||||
|
$show_date = isset( $instance['show_date'] ) ? (bool) $instance['show_date'] : false;
|
||||||
?>
|
?>
|
||||||
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
|
<p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
|
||||||
<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>
|
<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>
|
||||||
|
|
||||||
<p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number of posts to show:'); ?></label>
|
<p><label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of posts to show:' ); ?></label>
|
||||||
<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>
|
<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>
|
||||||
|
|
||||||
|
<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' ); ?>" />
|
||||||
|
<label for="<?php echo $this->get_field_id( 'show_date' ); ?>"><?php _e( 'Display post date?' ); ?></p>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue