'primebulletin_recent_post_widget', 'description' => esc_html__('Displays post form selected category specific for popular post in sidebars.', 'primebulletin'), 'customize_selective_refresh' => true, ); $fields = array( 'title' => array( 'label' => esc_html__('Title:', 'primebulletin'), 'type' => 'text', 'class' => 'widefat', ), 'post_category' => array( 'label' => esc_html__('Select Category:', 'primebulletin'), 'type' => 'dropdown-taxonomies', 'show_option_all' => esc_html__('All Categories', 'primebulletin'), ), 'enable_counter' => array( 'label' => esc_html__('Enable Counter:', 'primebulletin'), 'type' => 'checkbox', 'default' => true, ), 'post_number' => array( 'label' => esc_html__('Number of Posts:', 'primebulletin'), 'type' => 'number', 'default' => 4, 'css' => 'max-width:60px;', 'min' => 1, 'max' => 9, ), ); parent::__construct( 'PrimeBulletin-popular-sidebar-layout', esc_html__('PrimeBulletin: Sidebar Recent Post Widget', 'primebulletin'), $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']; if ( !empty( $params['title'] ) ) { echo $args['before_title'] . esc_html( $params['title'] ) . $args['after_title']; } $qargs = array( 'posts_per_page' => esc_attr( $params['post_number'] ), 'no_found_rows' => true, ); if ( absint( $params['post_category'] ) > 0 ) { $qargs['cat'] = absint($params['post_category']); } $recent_posts_query = new WP_Query( $qargs ); $count = 1; if ( $recent_posts_query->have_posts() ) : ?>