'stm_widget_recent_entries', 'description' => __( 'Your site’s most recent Posts.', 'stm_motors_extends' ), ); parent::__construct( 'stm-recent-posts', __( 'STM Last Post', 'stm_motors_extends' ), $widget_ops ); $this->alt_option_name = 'stm_widget_recent_entries'; } /** * @param array $args * @param array $instance */ public function widget( $args, $instance ) { $cache = array(); if ( ! $this->is_preview() ) { $cache = wp_cache_get( 'stm_widget_recent_posts', 'widget' ); } if ( ! is_array( $cache ) ) { $cache = array(); } if ( ! isset( $args['widget_id'] ) ) { $args['widget_id'] = $this->id; } if ( isset( $cache[ $args['widget_id'] ] ) ) { echo esc_html( $cache[ $args['widget_id'] ] ); return; } ob_start(); $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'STM Recent Posts', 'stm_motors_extends' ); $number_of_posts = ( ! empty( $instance['number_of_posts'] ) ) ? $instance['number_of_posts'] : __( '1', 'stm_motors_extends' ); /** This filter is documented in wp-includes/default-widgets.php */ $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); if ( empty( $number_of_posts ) ) { $number_of_posts = 1; } /** * Filter the arguments for the Recent Posts widget. * * @since 3.4.0 * * @see WP_Query::get_posts() * * @param array $args An array of arguments used to retrieve the recent posts. */ $r = new WP_Query( apply_filters( 'widget_posts_args', array( 'posts_per_page' => $number_of_posts, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true, ) ) ); if ( $r->have_posts() ) : ?> have_posts() ) : $r->the_post(); ?>