Make WordPress Core

Ticket #40203: 40203.patch

File 40203.patch, 3.2 KB (added by dingo_bastard, 9 years ago)

Add post thumbnail to Recent posts widget

  • src/wp-includes/widgets/class-wp-widget-recent-posts.php

     
    5656                if ( ! $number )
    5757                        $number = 5;
    5858                $show_date = isset( $instance['show_date'] ) ? $instance['show_date'] : false;
     59                $show_thumbnail = isset( $instance['show_thumbnail'] ) ? $instance['show_thumbnail'] : false;
    5960
    6061                /**
    6162                 * Filters the arguments for the Recent Posts widget.
     
    8283                <ul>
    8384                <?php while ( $r->have_posts() ) : $r->the_post(); ?>
    8485                        <li>
     86                        <?php if ( $show_thumbnail && has_post_thumbnail() ) :
     87                                the_post_thumbnail( 'thumbnail' );
     88                        endif; ?>
    8589                                <a href="<?php the_permalink(); ?>"><?php get_the_title() ? the_title() : the_ID(); ?></a>
    8690                        <?php if ( $show_date ) : ?>
    8791                                <span class="post-date"><?php echo get_the_date(); ?></span>
     
    113117                $instance['title'] = sanitize_text_field( $new_instance['title'] );
    114118                $instance['number'] = (int) $new_instance['number'];
    115119                $instance['show_date'] = isset( $new_instance['show_date'] ) ? (bool) $new_instance['show_date'] : false;
     120                $instance['show_thumbnail'] = isset( $new_instance['show_thumbnail'] ) ? (bool) $new_instance['show_thumbnail'] : false;
    116121                return $instance;
    117122        }
    118123
     
    128133                $title     = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
    129134                $number    = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
    130135                $show_date = isset( $instance['show_date'] ) ? (bool) $instance['show_date'] : false;
     136                $show_thumbnail = isset( $instance['show_thumbnail'] ) ? (bool) $instance['show_thumbnail'] : false;
    131137?>
    132138                <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
    133                 <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" placeholder="<?php esc_attr_e( 'Recent Posts' ); ?>" type="text" value="<?php echo $title; ?>" /></p>
     139                <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>
    134140
    135141                <p><label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of posts to show:' ); ?></label>
    136142                <input class="tiny-text" id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>" type="number" step="1" min="1" value="<?php echo $number; ?>" size="3" /></p>
     
    137143
    138144                <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' ); ?>" />
    139145                <label for="<?php echo $this->get_field_id( 'show_date' ); ?>"><?php _e( 'Display post date?' ); ?></label></p>
     146
     147                <p><input class="checkbox" type="checkbox"<?php checked( $show_thumbnail ); ?> id="<?php echo $this->get_field_id( 'show_thumbnail' ); ?>" name="<?php echo $this->get_field_name( 'show_thumbnail' ); ?>" />
     148                <label for="<?php echo $this->get_field_id( 'show_thumbnail' ); ?>"><?php _e( 'Display post thumbnail?' ); ?></label></p>
    140149<?php
    141150        }
    142151}