'', 'number' => '', 'same_cat' => 'false', 'show_thumb' => 'false', 'show_excerpt' => '', 'thumb_size' => '', 'nothumb' => '', 'date_range' => '', 'show_date' => 'false', 'thumb_shape' => '', 'category' => '' ), $atts ); $title = (! empty ( $attributes ['title'] )) ? $attributes ['title'] : ''; $number = (! empty ( $attributes ['number'] )) ? absint ( $attributes ['number'] ) : 5; if (! $number) $number = 5; $same_cat = isset ( $attributes ['same_cat'] ) ? $attributes ['same_cat'] : 'false'; $show_thumb = isset($attributes['show_thumb']) ? $attributes ['show_thumb'] : 'false'; $show_excerpt = isset($attributes['show_excerpt']) ? $attributes ['show_excerpt'] : ''; $thumb_size = isset($attributes['thumb_size']) ? $attributes ['thumb_size'] : 'full'; $nothumb = isset($attributes['nothumb']) ? $attributes['nothumb'] : ''; $date_range = isset($attributes['date_range']) ? $attributes['date_range'] : ''; $show_date = isset($attributes['show_date']) ? $attributes['show_date'] : 'false'; $thumb_shape = isset($attributes['thumb_shape']) ? $attributes['thumb_shape'] : ''; $category = isset($attributes['category']) ? $attributes['category'] : ''; if ($nothumb == 'true') { $show_thumb = ''; } $use_thumb_size = 'large'; $additional_class = ""; if ($show_thumb != '') { if ($thumb_size == 'full') { $use_thumb_size = 'large'; } if ($thumb_size == 'small') { $use_thumb_size = 'thumbnail'; $additional_class = "small"; } if ($thumb_size == 'medium') { $use_thumb_size = 'medium'; $additional_class = "center"; } if ($thumb_size == 'square') { $use_thumb_size = 'joy-post-thumbnail-square'; $additional_class = 'center'; } } $additional_class .= ' post-count-'.$number; if ($same_cat == 'true') { global $post; $post_type = get_post_type($post->ID); $post_categories = get_the_category($post->ID); $post_category = ''; if ($post_categories) { $post_category = $post_categories[0]->cat_ID; } $args_query = apply_filters( 'widget_posts_args', array( 'posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true, 'post_type' => $post_type, 'cat' => $post_category ) ); if ($date_range != '') { $args_query['date_query'] = array( array( 'after' => $date_range ) ); } $r = new WP_Query( $args_query ); } else { $args_query = apply_filters( 'widget_posts_args', array( 'posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true ) ); if ($category != '') { $args_query['cat'] = $category; } if ($date_range != '') { $args_query['date_query'] = array( array( 'after' => $date_range ) ); } $r = new WP_Query( $args_query ); } ob_start(); if (!$is_widget) { $args = array(); $args ['before_title'] = '

'; $args ['after_title'] = '

'; $args ['before_widget'] = ''; } if ($r->have_posts()) : ?> 'widget_popular_posts', 'description' => esc_html__( "Your site’s most recent posts.", 'brunch-lite') ); parent::__construct('pb-latest-posts', esc_html__('Brunch Pro: Latest Posts', 'brunch-lite'), $widget_ops); $this->alt_option_name = 'widget_popular_posts'; } /** * Outputs the content for the current Recent Posts widget instance. * * @since 2.8.0 * @access public * * @param array $args Display arguments including 'before_title', 'after_title', * 'before_widget', and 'after_widget'. * @param array $instance Settings for the current Recent Posts widget instance. */ public function widget( $args, $instance ) { if ( ! isset( $args['widget_id'] ) ) { $args['widget_id'] = $this->id; } joy_latest_posts($instance, true, $args); } /** * Handles updating the settings for the current Recent Posts widget instance. * * @since 2.8.0 * @access public * * @param array $new_instance New settings for this instance as input by the user via * WP_Widget::form(). * @param array $old_instance Old settings for this instance. * @return array Updated settings to save. */ public function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = sanitize_text_field( $new_instance['title'] ); $instance['number'] = (int) $new_instance['number']; $instance['same_cat'] = isset( $new_instance['same_cat'] ) ? (bool) $new_instance['same_cat'] : false; $instance['show_thumb'] = isset( $new_instance['show_thumb'] ) ? (bool) $new_instance['show_thumb'] : false; $instance['thumb_size'] = sanitize_text_field( $new_instance['thumb_size'] ); $instance['date_range'] = sanitize_text_field( $new_instance['date_range'] ); $instance['show_excerpt'] = isset( $new_instance['show_excerpt'] ) ? (bool) $new_instance['show_excerpt'] : false; $instance['show_date'] = isset( $new_instance['show_date'] ) ? (bool) $new_instance['show_date'] : false; $instance['thumb_shape'] = sanitize_text_field( $new_instance['thumb_shape'] ); $instance['category'] = sanitize_text_field( $new_instance['category'] ); return $instance; } /** * Outputs the settings form for the Recent Posts widget. * * @since 2.8.0 * @access public * * @param array $instance Current settings. */ public function form( $instance ) { $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; $number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5; $same_cat = isset( $instance['same_cat'] ) ? (bool) $instance['same_cat'] : false; $show_thumb = isset( $instance['show_thumb'] ) ? (bool) $instance['show_thumb'] : false; $thumb_size = isset( $instance['thumb_size'] ) ? esc_attr( $instance['thumb_size'] ) : ''; $date_range = isset( $instance['date_range'] ) ? esc_attr( $instance['date_range'] ) : ''; $show_excerpt = isset( $instance['show_excerpt'] ) ? (bool) $instance['show_excerpt'] : false; $show_date = isset( $instance['show_date'] ) ? (bool) $instance['show_date'] : false; $thumb_shape = isset($instance['thumb_shape']) ? $instance['thumb_shape'] : ''; $category = isset($instance['category']) ? $instance['category'] : ''; $sizes = array("full" => esc_html__('Big image', 'brunch-lite'), 'small' => esc_html__('Small image on the left', 'brunch-lite'), 'medium' => esc_html__('Medium image center aligned', 'brunch-lite'), 'square' => esc_html__('Square image', 'brunch-lite')); $date_ranges = array("" => esc_html__('Any time', 'brunch-lite'), '1 week ago' => esc_html__('Last 7 days', 'brunch-lite'), '2 weeks ago' => esc_html__('Last 14 days', 'brunch-lite'), '1 month ago' => esc_html__('Last month', 'brunch-lite'), '1 year ago' => esc_html__('Last year', 'brunch-lite')); $thumb_shapes = array("" => esc_html__('Square', 'brunch-lite'), 'circle' => esc_html__('Circle', 'brunch-lite'), 'round' => esc_html__('Rounded', 'brunch-lite')); ?>

id="get_field_id( 'same_cat' ); ?>" name="get_field_name( 'same_cat' ); ?>" />

id="get_field_id( 'show_excerpt' ); ?>" name="get_field_name( 'show_excerpt' ); ?>" />

id="get_field_id( 'show_date' ); ?>" name="get_field_name( 'show_date' ); ?>" />

id="get_field_id( 'show_thumb' ); ?>" name="get_field_name( 'show_thumb' ); ?>" />