esc_html__('Recent Posts','blog-web'), 'no_of_post' => 3, 'show_date' => 1, ); return $defaults; } /** * Constructor. */ function __construct() { $opts = array( 'classname' => 'blog-web-recent-widget', 'description' => esc_html__('TM: Recent Post Widget', 'blog-web'), ); parent::__construct('blog-web-recent-post', esc_html__('TM: Recent Post Widget', 'blog-web'), $opts); } /** * Echo the widget content. */ public function widget( $args, $instance ){ if(!empty($instance)){ $instance = wp_parse_args( (array ) $instance, $this->defaults() ); $title = apply_filters( 'widget_title', !empty( $instance['title'] ) ? $instance['title'] : '', $instance, $this->id_base ); $show_date = absint( $instance['show_date'] ? 1 : 0); $no_of_post = absint( $instance['no_of_post']); if(!empty($title) || !empty($no_of_post) ) { $query = array('showposts' => $no_of_post, 'nopaging' => 0, 'post_status' => 'publish', 'ignore_sticky_posts' => 1); $loop = new WP_Query($query); echo $args['before_widget']; ?> have_posts()) : $loop->the_post(); ?>
defaults() ); $show_date = absint( $instance['show_date'] ); ?>
" class="widefat" />
/>