defaults = array( 'title' => esc_html__( 'Blogg Recent Posts', 'blogg' ), 'number' => 3, 'show_date' => true, ); parent::__construct( 'blogg-recent-posts', esc_html__( 'Blogg Recent Posts', 'blogg' ), array( 'description' => esc_html__( 'A widget that displays your recent posts from all categories or a category with thumbnails.', 'blogg' ), ) ); } /** * How to display the widget on the screen. * @param array $args Widget parameters. * @param array $instance Widget instance. */ public function widget( $args, $instance ) { $instance = wp_parse_args( $instance, $this->defaults ); $query = new WP_Query( array( 'posts_per_page' => absint( $instance['number'] ), 'ignore_sticky_posts' => true, ) ); if ( ! $query->have_posts() ) { return; } echo $args['before_widget']; // WPCS: XSS OK. $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); if ( $title ) { echo $args['before_title'], $title, $args['after_title']; // WPCS: XSS OK. } ?>
defaults ); ?>