'widget-recent-posts', 'description' => esc_html__( "Your site’s most recent Posts.", 'adelin'), 'customize_selective_refresh' => true, ); parent::__construct('adelin-recent-posts', esc_html__('Adelin - Recent Posts', 'adelin'), $widget_ops); $this->alt_option_name = 'widget_recent_posts'; } /** * Outputs the content for the current Recent Posts widget instance. * * @since 1.0.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; } $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : ''; /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); $number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 5; if ( ! $number ) $number = 5; $sort = isset( $instance['sort'] ) ? $instance['sort'] : 'date'; $category = isset( $instance['category'] ) ? $instance['category'] : ''; $tags = !empty( $instance['tags'] ) ? explode(',', $instance['tags']) : false; $animation = ( isset($instance['animation']) && in_array( $instance['animation'], array( 'fade', 'horizontal', 'vertical') ) ) ? $instance['animation'] : 'horizontal'; $query_args = array( 'posts_per_page' => $number, 'cat' => $category, 'tag_slug__in' => $tags, 'no_found_rows' => true, 'post_status' => 'publish', 'orderby' => $sort, 'ignore_sticky_posts' => true ); $presented = isset( $instance['presentation'] ) ? $instance['presentation'] : 'thumbnail'; $slider_opt = json_encode ( array ( 'slideshow' => ( isset($instance['slideshow']) && $instance['slideshow'] == 'slideshow' ) ? true : false, 'slideshow_time' => isset( $instance['slideshow_time'] ) ? $instance['slideshow_time'] * 1000 : 5000, 'maxItems' => $presented == 'image-overlay' ? 3 : 4, 'itemMargin' => $presented == 'image-overlay' ? 0 : 40, 'animation' => ( $animation == 'fade' ) ? 'fade' : 'slide', 'direction' => ( $animation !== 'fade') ? $animation : null, ) ); if ( isset($instance['is_slider'] ) && $instance['is_slider'] == 'slider' ) { $slider_class = ' posts-slider'; $is_slider = true; $attr_slider_opt = 'data-slider-options="' . esc_attr($slider_opt) . '"'; $title = empty( $title ) ? ' ' : $title; } else { $slider_class = ''; $is_slider = false; $attr_slider_opt = ''; } $featured = new WP_Query( $query_args ); if ( $featured->have_posts() ) { //if ( $presented == '') echo $args['before_widget']; if ( ! empty( $title ) ) echo $args['before_title'] . $title . $args['after_title']; $classes = $presented . '-view' . $slider_class . ' sort-' . $sort; echo '
'; if ( $is_slider ) echo '
'; while ( $featured->have_posts() ) : $featured->the_post(); if ( $presented == 'small-thumbnail') get_template_part( 'template-parts/content-list-small', get_post_format() ); else get_template_part( 'template-parts/content-list', get_post_format() ); endwhile; wp_reset_postdata(); if ( $is_slider ) echo '
'; echo '
'; echo $args['after_widget']; } } /** * Handles updating the settings for the current Recent Posts widget instance. * * @since 1.0.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'] = absint( $new_instance['number'] ); $instance['sort'] = $new_instance['sort']; $instance['category'] = $new_instance['category']; $instance['tags'] = sanitize_text_field( $new_instance['tags'] ); $instance['presentation'] = sanitize_text_field( $new_instance['presentation'] ); $instance['slideshow'] = $new_instance['slideshow']; $instance['slideshow_time'] = absint( $new_instance['slideshow_time'] ); $instance['animation'] = $new_instance['animation']; $instance['is_slider'] = $new_instance['is_slider'] == 'slider' ? 'slider' : false ; return $instance; } /** * Outputs the settings form for the Recent Posts widget. * * @since 1.0.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; $show_date = isset( $instance['show_date'] ) ? (bool) $instance['show_date'] : false; $sort = isset( $instance['sort'] ) ? esc_attr( $instance['sort'] ) : 'date'; $category = isset( $instance['category'] ) ? $instance['category'] : ''; $tags = isset( $instance['tags'] ) ? esc_attr( $instance['tags'] ) : ''; $presentation = isset( $instance['presentation'] ) ? esc_attr( $instance['presentation'] ) : 'thumbnail'; $slideshow = isset( $instance['slideshow'] ) ? (bool) $instance['slideshow'] : false; $slideshow_time = isset( $instance['slideshow_time'] ) ? absint( $instance['slideshow_time'] ) : 5; $animation = isset( $instance['animation'] ) ? esc_attr( $instance['animation'] ) : 'fade'; $is_slider = isset( $instance['is_slider'] ) ? esc_attr( $instance['is_slider'] ) : false; ?>

esc_html__('All Categories', 'adelin'), 'name' => $this->get_field_name( 'category' ), 'id' => $this->get_field_id( 'category' ), 'selected' => $category, 'class' => 'widefat', ) ); ?>


/>
/>
/>
/>
/>