'', 'category' => '', 'random' => '', 'count' => 3, ); function __construct() { $widget_ops = array( 'description' => esc_html__( 'Displays a number of the latest (or random) posts from a specific category.', 'brittany-light' ) ); $control_ops = array(); parent::__construct( 'ci-latest-posts', esc_html__( 'Theme - Latest Posts', 'brittany-light' ), $widget_ops, $control_ops ); } function widget( $args, $instance ) { extract( $args ); $instance = wp_parse_args( (array) $instance, $this->defaults ); $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); $category = $instance['category']; $random = $instance['random']; $count = $instance['count']; if ( 0 == $count ) { return; } $args = array( 'orderby' => 'date', 'order' => 'DESC', 'posts_per_page' => $count ); if ( 1 == $random ) { $args['orderby'] = 'rand'; unset( $args['order'] ); } if ( ! empty( $category ) && $category > 0 ) { $args['cat'] = intval( $category ); } $q = new WP_Query( $args ); if ( $q->have_posts() ) { echo $before_widget; if ( ! empty( $title ) ) { echo $before_title . $title . $after_title; } while ( $q->have_posts() ) { $q->the_post(); get_template_part( 'item-media', get_post_type() ); } wp_reset_postdata(); echo $after_widget; } } // widget function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = sanitize_text_field( $new_instance['title'] ); $instance['category'] = brittany_light_sanitize_intval_or_empty( $new_instance['category'] ); $instance['random'] = brittany_light_sanitize_checkbox( $new_instance['random'] ); $instance['count'] = intval( $new_instance['count'] ) > 0 ? intval( $new_instance['count'] ) : 1; return $instance; } // save function form( $instance ) { $instance = wp_parse_args( (array) $instance, $this->defaults ); $title = $instance['title']; $category = $instance['category']; $random = $instance['random']; $count = $instance['count']; ?>

'category', 'show_option_all' => '', 'show_option_none' => ' ', 'option_none_value' => '', 'show_count' => 1, 'echo' => 1, 'selected' => $category, 'hierarchical' => 1, 'name' => $this->get_field_name( 'category' ), 'id' => $this->get_field_id( 'category' ), 'class' => 'postform widefat', ) ); ?>