widget_cssclass = 'avenews-widget-slider avenews-fullwidth-widget'; $this->widget_description = __("Displays featured posts with an image on slider", 'avenews'); $this->widget_id = 'Avenews_Slider_Widget'; $this->widget_name = __('Avenews: Slider Widget', 'avenews'); $this->settings = array( 'title' => array( 'type' => 'text', 'label' => __('Title', 'avenews'), ), 'category' => array( 'type' => 'dropdown-taxonomies', 'label' => __('Select Category', 'avenews'), 'desc' => __('Leave empty if you don\'t want the posts to be category specific', 'avenews'), 'args' => array( 'taxonomy' => 'category', 'class' => 'widefat', 'hierarchical' => true, 'show_count' => 1, 'show_option_all' => __('— Select —', 'avenews'), ), ), 'number' => array( 'type' => 'number', 'step' => 1, 'min' => 2, 'max' => 12, 'std' => 6, 'label' => __('Number of posts to show', 'avenews'), ), 'button_text' => array( 'type' => 'text', 'label' => __('Button Text', 'avenews'), 'std' => 'Explore in Detail Now!', ), 'show_overlay' => array( 'type' => 'checkbox', 'label' => __('Show Overlay', 'avenews'), 'std' => true, ), 'title_size' => array( 'type' => 'select', 'label' => __('Title font size', 'avenews'), 'options' => array( 'entry-title-large' => __('Large', 'avenews'), 'entry-title-big' => __('Big', 'avenews'), 'entry-title-medium' => __('Medium', 'avenews'), 'entry-title-small' => __('Small', 'avenews'), ), 'std' => 'entry-title-big', ), 'show_category' => array( 'type' => 'checkbox', 'label' => __('Show Category', 'avenews'), 'std' => true, ), 'has_category_bg' => array( 'type' => 'checkbox', 'label' => __('Category Background Color', 'avenews'), 'std' => true, ), 'show_description' => array( 'type' => 'checkbox', 'label' => __('Show Description', 'avenews'), 'std' => false, ), 'show_author' => array( 'type' => 'checkbox', 'label' => __('Show Author', 'avenews'), 'std' => false, ), 'show_date' => array( 'type' => 'checkbox', 'label' => __('Show Date', 'avenews'), 'std' => true, ), 'bg_color_option' => array( 'type' => 'color', 'label' => __('Background Color', 'avenews'), 'std' => '#222222', ), 'text_color_option' => array( 'type' => 'color', 'label' => __('Text Color', 'avenews'), 'std' => '#ffffff', ), 'bg_image' => array( 'type' => 'image', 'label' => __('Background Image', 'avenews'), 'desc' => __('Don\'t upload any image if you do not want to show the background image.', 'avenews'), ), 'overlay_opacity' => array( 'type' => 'number', 'step' => 10, 'min' => 0, 'max' => 100, 'std' => 50, 'label' => __('Overlay Opacity (Default 50%)', 'avenews'), ), 'bg_overlay_color' => array( 'type' => 'color', 'label' => __('Overlay Background Color', 'avenews'), 'std' => '#000000', ), ); parent::__construct(); } /** * Query the posts and return them. * @param array $args * @param array $instance * @return WP_Query */ public function get_posts($args, $instance) { $number = !empty($instance['number']) ? absint($instance['number']) : $this->settings['number']['std']; $query_args = array( 'posts_per_page' => $number, 'post_status' => 'publish', 'no_found_rows' => 1, 'ignore_sticky_posts' => 1 ); if (!empty($instance['category']) && -1 != $instance['category'] && 0 != $instance['category']) { $query_args['tax_query'][] = array( 'taxonomy' => 'category', 'field' => 'term_id', 'terms' => $instance['category'], ); } return new WP_Query(apply_filters('Avenews_Slider_Widget_query_args', $query_args)); } /** * Output widget. * * @param array $args * @param array $instance * @see WP_Widget * */ public function widget($args, $instance) { ob_start(); $class = ''; $image_enabled = !empty($instance['bg_image']); $bg_color_option = ""; if (isset($instance['bg_color_option'])) { $bg_color_option = $instance['bg_color_option']; } $style_text = 'color:' . $instance['text_color_option'] . ';'; $style_text .= 'background-color:' . $bg_color_option . ';'; $style = 'background-color:' . $instance['bg_overlay_color'] . ';'; $style .= 'opacity:' . ($instance['overlay_opacity'] / 100) . ';'; $site_fallback_image = avenews_get_option('site_fallback_image'); $widget_button_text = $instance['button_text']; $slider_pagenav = ''; $banner_overlay = ''; if ($instance['show_overlay']) { $banner_overlay = 'swiper-slide-has-overlay'; } echo $args['before_widget']; do_action('avenews_before_slider_widget'); ?>