'asterisk_lite_recent_post_widget', 'description' => esc_html__('Displays post form selected category specific for popular post in sidebars.', 'asterisk-lite'), 'customize_selective_refresh' => true, ); $category_list = asterisk_lite_post_category_list(); $fields = array( 'title' => array( 'label' => esc_html__('Title:', 'asterisk-lite'), 'type' => 'text', 'class' => 'widefat', ), 'post_category' => array( 'label' => esc_html__('Select Category:', 'asterisk-lite'), 'type' => 'select', 'options' => $category_list, ), 'post_number' => array( 'label' => esc_html__('Number of posts to show:', 'asterisk-lite'), 'type' => 'number', 'default' => 5, 'css' => 'max-width:60px;', 'min' => 1, 'max' => 10, ), 'display_style' => array( 'label' => esc_html__('Layout:', 'asterisk-lite'), 'type' => 'select', 'default' => 'layout-1', 'options' => array( 'layout-1' => esc_html__('Layout One','asterisk-lite'), 'layout-2' => esc_html__('Layout Two','asterisk-lite'), ), ), ); parent::__construct( 'asterisk-lite-recent-posts', esc_html__('Devs: Sidebar Recent Post Widget', 'asterisk-lite'), $opts, array(), $fields ); } /** * Outputs the content for the current widget instance. * * @since 1.0.0 * * @param array $args Display arguments. * @param array $instance Settings for the current widget instance. */ function widget( $args, $instance ){ $params = $this->get_params( $instance ); echo $args['before_widget']; $title = isset( $params['title'] ) ? $params['title'] : ''; $post_number = isset( $params['post_number'] ) ? $params['post_number'] : ''; $post_category = isset( $params['post_category'] ) ? $params['post_category'] : ''; $display_style = isset( $params['display_style'] ) ? $params['display_style'] : ''; if( $title ){ echo $args['before_title'] . esc_html( $title ) . $args['after_title']; } $qargs = array( 'posts_per_page' => esc_attr( $post_number ), 'no_found_rows' => true, ); if( $display_style == 'layout-2' ){ $size = 'medium'; }else{ $size = 'thumbnail'; } $recent_posts_query = new WP_Query( $qargs ); $count = 1; if ( $recent_posts_query->have_posts() ) : ?>