widget_cssclass = 'widget_blogbyte_posts_carousel'; $this->widget_description = __( 'Displays posts in carousel', 'blogbyte' ); $this->widget_id = 'blogbyte_posts_carousel'; $this->widget_name = __( 'Blogbyte: Posts Carousel', 'blogbyte' ); $this->settings = array( 'title' => array( 'type' => 'text', 'label' => __( 'Title', 'blogbyte' ), ), 'post_settings_heading' => array( 'type' => 'heading', 'label' => __( 'Post Settings', 'blogbyte' ), ), 'category' => array( 'type' => 'dropdown-taxonomies', 'label' => __( 'Select Category', 'blogbyte' ), 'desc' => __( 'Leave empty if you don\'t want the posts to be category specific', 'blogbyte' ), 'args' => array( 'taxonomy' => 'category', 'class' => 'widefat', 'hierarchical' => true, 'show_count' => 1, 'show_option_all' => __( '— Select —', 'blogbyte' ), ), ), 'number' => array( 'type' => 'number', 'step' => 1, 'min' => 1, 'max' => '', 'std' => 5, 'label' => __( 'Number of posts to show', 'blogbyte' ), ), 'offset' => array( 'type' => 'number', 'step' => 1, 'min' => 0, 'max' => '', 'std' => '', 'label' => __( 'Offset', 'blogbyte' ), 'desc' => __( 'Can be useful if you want to skip certain number of posts. Leave as 0 if you do not want to use it.', 'blogbyte' ), ), 'orderby' => array( 'type' => 'select', 'std' => 'date', 'label' => __( 'Order by', 'blogbyte' ), 'options' => array( 'date' => __( 'Date', 'blogbyte' ), 'ID' => __( 'ID', 'blogbyte' ), 'title' => __( 'Title', 'blogbyte' ), 'rand' => __( 'Random', 'blogbyte' ), ), ), 'order' => array( 'type' => 'select', 'std' => 'desc', 'label' => __( 'Order', 'blogbyte' ), 'options' => array( 'asc' => __( 'ASC', 'blogbyte' ), 'desc' => __( 'DESC', 'blogbyte' ), ), ), 'meta_settings_heading' => array( 'type' => 'heading', 'label' => __( 'Post Meta Settings', 'blogbyte' ), ), 'post_meta' => array( 'type' => 'multi-checkbox', 'label' => __( 'Post Meta', 'blogbyte' ), 'options' => array( 'author' => __( 'Author', 'blogbyte' ), 'read_time' => __( 'Post Read Time', 'blogbyte' ), 'date' => __( 'Date', 'blogbyte' ), 'comment' => __( 'Comment', 'blogbyte' ), ), 'std' => array(), ), 'post_meta_icon' => array( 'type' => 'checkbox', 'label' => __( 'Show Post Meta Icon', 'blogbyte' ), 'desc' => __( 'Some Icons may show up regardless to provide better info.', 'blogbyte' ), 'std' => true, ), 'date_format' => array( 'type' => 'select', 'label' => __( 'Date Format', 'blogbyte' ), 'desc' => __( 'Make sure to select Date from above for this to work.', 'blogbyte' ), 'options' => array( 'format_1' => __( 'Times Ago', 'blogbyte' ), 'format_2' => __( 'Default Format', 'blogbyte' ), ), 'std' => 'format_1', ), 'author_image' => array( 'type' => 'checkbox', 'label' => __( 'Show Author Image', 'blogbyte' ), 'desc' => __( 'Make sure to select Author from above for this to work.', 'blogbyte' ), 'std' => false, ), 'excerpt_settings_heading' => array( 'type' => 'heading', 'label' => __( 'Excerpt Settings', 'blogbyte' ), ), 'show_excerpt' => array( 'type' => 'checkbox', 'label' => __( 'Show Excerpt', 'blogbyte' ), 'std' => false, ), 'excerpt_length' => array( 'type' => 'number', 'step' => 1, 'min' => 0, 'max' => '', 'std' => 20, 'label' => __( 'Excerpt Length', 'blogbyte' ), ), 'show_read_more' => array( 'type' => 'checkbox', 'label' => __( 'Show Read More', 'blogbyte' ), 'std' => false, ), 'read_more_text' => array( 'type' => 'text', 'label' => __( 'Read More Text', 'blogbyte' ), 'desc' => __( 'Leave Empty if you want to use default text "Read More" ', 'blogbyte' ), ), 'read_more_style' => array( 'type' => 'select', 'label' => __( 'Read More Style', 'blogbyte' ), 'options' => blogbyte_get_read_more_styles(), 'std' => 'style_2', ), 'read_more_icon' => array( 'type' => 'select', 'label' => __( 'Read More Icon', 'blogbyte' ), 'options' => blogbyte_get_read_more_icons_list(), 'std' => 'arrow-right', ), 'category_settings_heading' => array( 'type' => 'heading', 'label' => __( 'Category Settings', 'blogbyte' ), ), 'show_category' => array( 'type' => 'checkbox', 'label' => __( 'Show Category', 'blogbyte' ), 'std' => true, ), 'category_color' => array( 'type' => 'select', 'label' => __( 'Category Color', 'blogbyte' ), 'options' => blogbyte_get_category_color_display(), 'std' => 'as_bg', ), 'category_style' => array( 'type' => 'select', 'label' => __( 'Category Style', 'blogbyte' ), 'options' => blogbyte_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', 'blogbyte' ), ), 'widget_settings_heading' => array( 'type' => 'heading', 'label' => __( 'Widget Settings', 'blogbyte' ), ), 'style' => array( 'type' => 'select', 'label' => __( 'Display Style', 'blogbyte' ), 'options' => array( 'style_1' => __( 'Style 1', 'blogbyte' ), 'style_2' => __( 'Style 2', 'blogbyte' ), ), 'std' => 'style_1', ), 'justify_content' => array( 'type' => 'checkbox', 'label' => __( 'Center Content', 'blogbyte' ), 'std' => false, ), 'margin' => array( 'type' => 'number', 'step' => 1, 'min' => 0, 'max' => 100, 'std' => 24, 'label' => __( 'Carousel margin', 'blogbyte' ), ), 'autoplay' => array( 'type' => 'checkbox', 'label' => __( 'Autoplay', 'blogbyte' ), 'std' => false, ), 'arrows' => array( 'type' => 'checkbox', 'label' => __( 'Enable Arrows', 'blogbyte' ), 'std' => true, ), 'dots' => array( 'type' => 'checkbox', 'label' => __( 'Enable Dots', 'blogbyte' ), 'std' => false, ), 'column' => array( 'type' => 'number', 'step' => 1, 'min' => 1, 'max' => 5, 'std' => 3, 'label' => __( 'Column', 'blogbyte' ), ), 'enable_post_format_icon' => array( 'type' => 'checkbox', 'label' => __( 'Enable Post Format Icon', 'blogbyte' ), 'std' => false, ), 'inverted_block_color' => array( 'type' => 'checkbox', 'label' => __( 'Inverted Color', 'blogbyte' ), 'desc' => __( 'Can be used if you have dark background and want lighter color on the text.', 'blogbyte' ), 'std' => false, ), 'title_limit' => array( 'type' => 'select', 'label' => __( 'Post Title Limit', 'blogbyte' ), 'options' => blogbyte_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( 'blogbyte_posts_carousel_query_args', $query_args ) ); } /** * Output widget. * * @see WP_Widget * * @param array $args * @param array $instance */ public function widget( $args, $instance ) { ob_start(); if ( ( $posts = $this->get_posts( $args, $instance ) ) && $posts->have_posts() ) { $this->widget_start( $args, $instance ); do_action( 'blogbyte_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; $img_class = ''; $margin = isset( $instance['margin'] ) ? absint( $instance['margin'] ) : $this->settings['margin']['std']; if ( $margin != 0 ) { $img_class .= ' blogbyte-rounded-img'; } $autoplay = isset( $instance['autoplay'] ) ? $instance['autoplay'] : $this->settings['autoplay']['std']; $dots = isset( $instance['dots'] ) ? $instance['dots'] : $this->settings['dots']['std']; if ( $dots ) { $slider_nav .= '
'; $wrapper_class .= ' blogbyte-swiper-outer-bullets'; } $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, 'disableOnInteraction' => false, ); 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 .= ' saga-block-inverted-color'; } // Justify Content. $justify_content = isset( $instance['justify_content'] ) ? $instance['justify_content'] : $this->settings['justify_content']['std']; if ( $justify_content ) { $wrapper_class .= ' blogbyte-justify-article-contents'; } ?> widget_end( $args ); } echo ob_get_clean(); } }