'bazzinga_widget_recent_posts', 'description' => __( 'Displays recent posts.', 'bazzinga' ), 'customize_selective_refresh' => true, ); $fields = array( 'title' => array( 'label' => __( 'Title:', 'bazzinga' ), 'type' => 'text', ), 'post_category' => array( 'label' => __( 'Select Category:', 'bazzinga' ), 'type' => 'dropdown-taxonomies', 'show_option_all' => __( 'All Categories', 'bazzinga' ), ), 'post_number' => array( 'label' => __( 'Number of Posts:', 'bazzinga' ), 'type' => 'number', 'default' => 4, 'css' => 'max-width:60px;', 'min' => 1, 'max' => 100, ), 'disable_date' => array( 'label' => __( 'Disable Date', 'bazzinga' ), 'type' => 'checkbox', 'default' => false, ), ); parent::__construct( 'bazzinga-recent-posts', __( 'bazz: Recent Posts', 'bazzinga' ), $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'] . $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'] = $params['post_category']; } $all_posts = get_posts( $qargs ); ?>