widget_cssclass = 'widget_blogmarks_posts_carousel'; $this->widget_description = __('Displays posts in carousel', 'blogmarks'); $this->widget_id = 'blogmarks_posts_carousel'; $this->widget_name = __('Blogmarks: Posts Carousel', 'blogmarks'); $this->settings = array( 'title' => array( 'type' => 'text', 'label' => __('Title', 'blogmarks'), ), 'post_settings_heading' => array( 'type' => 'heading', 'label' => __('Post Settings', 'blogmarks'), ), 'category' => array( 'type' => 'dropdown-taxonomies', 'label' => __('Select Category', 'blogmarks'), 'desc' => __('Leave empty if you don\'t want the posts to be category specific', 'blogmarks'), 'args' => array( 'taxonomy' => 'category', 'class' => 'widefat', 'hierarchical' => true, 'show_count' => 1, 'show_option_all' => __('— Select —', 'blogmarks'), ), ), 'number' => array( 'type' => 'number', 'step' => 1, 'min' => 1, 'max' => '', 'std' => 5, 'label' => __('Number of posts to show', 'blogmarks'), ), 'offset' => array( 'type' => 'number', 'step' => 1, 'min' => 0, 'max' => '', 'std' => '', 'label' => __('Offset', 'blogmarks'), 'desc' => __('Can be useful if you want to skip certain number of posts. Leave as 0 if you do not want to use it.', 'blogmarks'), ), 'orderby' => array( 'type' => 'select', 'std' => 'date', 'label' => __('Order by', 'blogmarks'), 'options' => array( 'date' => __('Date', 'blogmarks'), 'ID' => __('ID', 'blogmarks'), 'title' => __('Title', 'blogmarks'), 'rand' => __('Random', 'blogmarks'), ), ), 'order' => array( 'type' => 'select', 'std' => 'desc', 'label' => __('Order', 'blogmarks'), 'options' => array( 'asc' => __('ASC', 'blogmarks'), 'desc' => __('DESC', 'blogmarks'), ), ), 'meta_settings_heading' => array( 'type' => 'heading', 'label' => __('Post Meta Settings', 'blogmarks'), ), 'post_meta' => array( 'type' => 'multi-checkbox', 'label' => __('Post Meta', 'blogmarks'), 'options' => array( 'author' => __('Author', 'blogmarks'), 'read_time' => __('Post Read Time', 'blogmarks'), 'date' => __('Date', 'blogmarks'), 'comment' => __('Comment', 'blogmarks'), ), 'std' => array(), ), 'post_meta_icon' => array( 'type' => 'checkbox', 'label' => __('Show Post Meta Icon', 'blogmarks'), 'desc' => __('Some Icons may show up regardless to provide better info.', 'blogmarks'), 'std' => true, ), 'date_format' => array( 'type' => 'select', 'label' => __('Date Format', 'blogmarks'), 'desc' => __('Make sure to select Date from above for this to work.', 'blogmarks'), 'options' => array( 'format_1' => __('Times Ago', 'blogmarks'), 'format_2' => __('Default Format', 'blogmarks'), ), 'std' => 'format_1', ), 'author_image' => array( 'type' => 'checkbox', 'label' => __('Show Author Image', 'blogmarks'), 'desc' => __('Make sure to select Author from above for this to work.', 'blogmarks'), 'std' => false, ), 'excerpt_settings_heading' => array( 'type' => 'heading', 'label' => __('Excerpt Settings', 'blogmarks'), ), 'show_excerpt' => array( 'type' => 'checkbox', 'label' => __('Show Excerpt', 'blogmarks'), 'std' => false, ), 'excerpt_length' => array( 'type' => 'number', 'step' => 1, 'min' => 0, 'max' => '', 'std' => 20, 'label' => __('Excerpt Length', 'blogmarks'), ), 'show_read_more' => array( 'type' => 'checkbox', 'label' => __('Show Read More', 'blogmarks'), 'std' => false, ), 'read_more_text' => array( 'type' => 'text', 'label' => __('Read More Text', 'blogmarks'), 'desc' => __('Leave Empty if you want to use default text "Read More" ', 'blogmarks'), ), 'read_more_style' => array( 'type' => 'select', 'label' => __('Read More Style', 'blogmarks'), 'options' => blogmarks_get_read_more_styles(), 'std' => 'style_2', ), 'read_more_icon' => array( 'type' => 'select', 'label' => __('Read More Icon', 'blogmarks'), 'options' => blogmarks_get_read_more_icons_list(), 'std' => 'arrow-right', ), 'category_settings_heading' => array( 'type' => 'heading', 'label' => __('Category Settings', 'blogmarks'), ), 'show_category' => array( 'type' => 'checkbox', 'label' => __('Show Category', 'blogmarks'), 'std' => true, ), 'category_color' => array( 'type' => 'select', 'label' => __('Category Color', 'blogmarks'), 'options' => blogmarks_get_category_color_display(), 'std' => 'as_bg', ), 'category_style' => array( 'type' => 'select', 'label' => __('Category Style', 'blogmarks'), 'options' => blogmarks_get_category_styles(), 'std' => 'style_2', ), 'no_of_category' => array( 'type' => 'number', 'step' => 1, 'min' => 0, 'max' => '', 'std' => 1, 'label' => __('Number of Category to Display', 'blogmarks'), ), 'widget_settings_heading' => array( 'type' => 'heading', 'label' => __('Widget Settings', 'blogmarks'), ), 'style' => array( 'type' => 'select', 'label' => __('Display Style', 'blogmarks'), 'options' => array( 'style_1' => __('Style 1', 'blogmarks'), 'style_2' => __('Style 2', 'blogmarks'), ), 'std' => 'style_1', ), 'image_size' => array( 'type' => 'select', 'std' => 'medium_large', 'label' => __('Featured Image Size', 'blogmarks'), 'options' => array( 'large' => __('Large', 'blogmarks'), 'medium_large' => __('Medium Large', 'blogmarks'), 'medium' => __('Medium', 'blogmarks'), 'small' => __('Small', 'blogmarks'), ), ), 'margin' => array( 'type' => 'number', 'step' => 1, 'min' => 0, 'max' => 100, 'std' => 24, 'label' => __('Carousel margin', 'blogmarks'), ), 'autoplay' => array( 'type' => 'checkbox', 'label' => __('Autoplay', 'blogmarks'), 'std' => false, ), 'arrows' => array( 'type' => 'checkbox', 'label' => __('Enable Arrows', 'blogmarks'), 'std' => true, ), 'dots' => array( 'type' => 'checkbox', 'label' => __('Enable Dots', 'blogmarks'), 'std' => false, ), 'column' => array( 'type' => 'number', 'step' => 1, 'min' => 1, 'max' => 5, 'std' => 3, 'label' => __('Column', 'blogmarks'), ), 'enable_post_format_icon' => array( 'type' => 'checkbox', 'label' => __('Enable Post Format Icon', 'blogmarks'), 'std' => false, ), 'inverted_block_color' => array( 'type' => 'checkbox', 'label' => __('Inverted Color', 'blogmarks'), 'desc' => __('Can be used if you have dark background and want lighter color on the text.', 'blogmarks'), 'std' => false, ), 'title_limit' => array( 'type' => 'select', 'label' => __('Title Line Limit', 'blogmarks'), 'options' => blogmarks_get_title_limit_choices(), 'std' => '', ), ); 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']; $orderby = !empty($instance['orderby']) ? sanitize_title($instance['orderby']) : $this->settings['orderby']['std']; $order = !empty($instance['order']) ? sanitize_title($instance['order']) : $this->settings['order']['std']; $offset = !empty($instance['offset']) ? sanitize_text_field($instance['offset']) : $this->settings['offset']['std']; $query_args = array( 'posts_per_page' => $number, 'post_status' => 'publish', 'no_found_rows' => 1, 'orderby' => $orderby, 'order' => $order, 'ignore_sticky_posts' => 1, ); if ($offset && 0 != $offset) { $query_args['offset'] = absint($offset); } 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('blogmarks_posts_carousel_query_args', $query_args)); } /** * Output widget. * * @param array $args * @param array $instance * @see WP_Widget * */ public function widget($args, $instance) { ob_start(); if (($posts = $this->get_posts($args, $instance)) && $posts->have_posts()) { $this->widget_start($args, $instance); do_action('blogmarks_before_posts_carousel'); $overlay = $wrapper_class = $slider_nav = ''; $display_style = isset($instance['style']) ? $instance['style'] : $this->settings['style']['std']; if ('style_2' == $display_style) { $overlay = ''; } $wrapper_class = $display_style; $margin = isset($instance['margin']) ? absint($instance['margin']) : $this->settings['margin']['std']; $autoplay = isset($instance['autoplay']) ? $instance['autoplay'] : $this->settings['autoplay']['std']; $dots = isset($instance['dots']) ? $instance['dots'] : $this->settings['dots']['std']; if ($dots) { $slider_nav .= '
'; } $arrows = isset($instance['arrows']) ? $instance['arrows'] : $this->settings['arrows']['std']; if ($arrows) { $slider_nav .= ''; } $column = isset($instance['column']) ? absint($instance['column']) : $this->settings['column']['std']; $wrapper_class .= " column-$column"; // Build attributes. $data_slider = array(); $data_slider['spaceBetween'] = $margin; if ($autoplay) : $data_slider['autoplay'] = array( 'delay' => 5000, ); endif; if ($column == 2) { $data_slider['breakpoints'] = array( '576' => array( 'slidesPerView' => 2, ), ); } elseif ($column == 3) { $data_slider['breakpoints'] = array( '576' => array( 'slidesPerView' => 2, ), '768' => array( 'slidesPerView' => 3, ), ); } elseif ($column == 4) { $data_slider['breakpoints'] = array( '576' => array( 'slidesPerView' => 2, ), '768' => array( 'slidesPerView' => 3, ), '992' => array( 'slidesPerView' => 4, ), ); } elseif ($column == 5) { $data_slider['breakpoints'] = array( '576' => array( 'slidesPerView' => 2, ), '768' => array( 'slidesPerView' => 3, ), '992' => array( 'slidesPerView' => 4, ), '1200' => array( 'slidesPerView' => 5, ), ); } $show_category = isset($instance['show_category']) ? $instance['show_category'] : $this->settings['show_category']['std']; if ($show_category) { $cat_style = isset($instance['category_style']) ? $instance['category_style'] : $this->settings['category_style']['std']; $color = isset($instance['category_color']) ? $instance['category_color'] : $this->settings['category_color']['std']; $limit = isset($instance['no_of_category']) ? $instance['no_of_category'] : $this->settings['no_of_category']['std']; } $enabled_post_meta = isset($instance['post_meta']) ? $instance['post_meta'] : $this->settings['post_meta']['std']; $meta_settings['date_format'] = isset($instance['date_format']) ? $instance['date_format'] : $this->settings['date_format']['std']; $meta_settings['author_image'] = isset($instance['author_image']) ? $instance['author_image'] : $this->settings['author_image']['std']; $meta_settings['show_icons'] = isset($instance['post_meta_icon']) ? $instance['post_meta_icon'] : $this->settings['post_meta_icon']['std']; $title_limit = isset($instance['title_limit']) ? $instance['title_limit'] : $this->settings['title_limit']['std']; $enable_post_format_icon = isset($instance['enable_post_format_icon']) ? $instance['enable_post_format_icon'] : $this->settings['enable_post_format_icon']['std']; $show_excerpt = isset($instance['show_excerpt']) ? $instance['show_excerpt'] : $this->settings['show_excerpt']['std']; if ($show_excerpt) { $excerpt_length = isset($instance['excerpt_length']) ? $instance['excerpt_length'] : $this->settings['excerpt_length']['std']; } $show_read_more = isset($instance['show_read_more']) ? $instance['show_read_more'] : $this->settings['show_read_more']['std']; if ($show_read_more) { $read_more_text = isset($instance['read_more_text']) ? $instance['read_more_text'] : ''; $read_more_style = isset($instance['read_more_style']) ? $instance['read_more_style'] : $this->settings['read_more_style']['std']; $read_more_icon = isset($instance['read_more_icon']) ? $instance['read_more_icon'] : $this->settings['read_more_icon']['std']; } $inverted_block_color = isset($instance['inverted_block_color']) ? $instance['inverted_block_color'] : $this->settings['inverted_block_color']['std']; // Inverted Color. if ($inverted_block_color) { $wrapper_class .= ' widget-inverted-scheme'; } ?> widget_end($args); } echo ob_get_clean(); } }