'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 '
esc_html__('All Categories', 'adelin'), 'name' => $this->get_field_name( 'category' ), 'id' => $this->get_field_id( 'category' ), 'selected' => $category, 'class' => 'widefat', ) ); ?>
/>
/>
/>
/>