'widget_recent_entries_custom', 'description' => __( 'Recent posts with thumbnails', 'aari' ), 'customize_selective_refresh' => true, ); parent::__construct( 'Aari_Recentpost_Widget', __( 'Aari Latest Posts', 'aari' ), $widget_ops ); } private $widget_fields = array( array( 'id' => 'numberofpoststo_number', 'default' => '5', 'type' => 'number', ), array( 'id' => 'displaypostdate_checkbox', 'type' => 'checkbox', ), ); public function widget( $args, $instance ) { echo wp_kses_post( $args['before_widget'] ); if ( ! empty( $instance['title'] ) ) { echo wp_kses_post( $args['before_title'] . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $args['after_title'] ); } $aari_the_query = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => $instance['numberofpoststo_number'], 'post_status' => 'publish', 'orderby' => 'date', 'order' => 'DESC', 'post__not_in' => get_option( 'sticky_posts' ), ) ); echo '
'; $output .= ''; $output .= ''; $output .= '
'; break; default: $output .= ''; $output .= ' '; $output .= ''; $output .= '
'; } } echo $output; } public function form( $instance ) { $title = ! empty( $instance['title'] ) ? $instance['title'] : esc_html__( 'Recent Post', 'aari' ); ?>field_generator( $instance ); } public function update( $new_instance, $old_instance ) { $instance = array(); $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : ''; foreach ( $this->widget_fields as $widget_field ) { switch ( $widget_field['type'] ) { default: $instance[ $widget_field['id'] ] = ( ! empty( $new_instance[ $widget_field['id'] ] ) ) ? strip_tags( $new_instance[ $widget_field['id'] ] ) : ''; } } return $instance; } } function aari_recentpost_widget_register() { register_widget( 'Aari_Recentpost_Widget' ); } add_action( 'widgets_init', 'aari_recentpost_widget_register' );