widget_cssclass = 'avenews-widget-carousel'; $this->widget_description = __("Experience dynamic news presentation with our News Carousel Widget. Scroll through the latest updates seamlessly, enjoying a visually captivating display that brings news stories to life in an engaging and informative manner.", 'avenews'); $this->widget_id = 'Avenews_Carousel_Widget'; $this->widget_name = __('Avenews: News Carousel', 'avenews'); $this->settings = array( 'title' => array( 'type' => 'text', 'label' => __('Title', 'avenews'), ), 'title_size' => array( 'type' => 'select', 'label' => __('Title font size', 'avenews'), 'options' => array( 'entry-title-medium' => __('Medium', 'avenews'), 'entry-title-small' => __('Small', 'avenews'), ), 'std' => 'entry-title-small', ), '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'), ), 'slider_per_view' => array( 'type' => 'number', 'step' => 1, 'min' => 2, 'max' => 4, 'std' => 3, 'label' => __('Slides Per View', 'avenews'), ), 'centered_slides' => array( 'type' => 'checkbox', 'label' => __('Centered Slides', 'avenews'), 'std' => false, ), 'autoplay' => array( 'type' => 'checkbox', 'label' => __('Autoplay', 'avenews'), 'std' => true, ), 'space_between' => array( 'type' => 'select', 'label' => __('space Between', 'avenews'), 'options' => array( '0' => __('0', 'avenews'), '5' => __('5', 'avenews'), '10' => __('10', 'avenews'), '15' => __('15', 'avenews'), '20' => __('20', 'avenews'), '25' => __('25', 'avenews'), '30' => __('30', 'avenews'), ), 'std' => '20', ), 'pagination' => array( 'type' => 'checkbox', 'label' => __('Pagination', 'avenews'), 'std' => true, ), 'image_size' => array( 'type' => 'select', 'label' => __('Image size', 'avenews'), 'options' => array( 'entry-image-medium' => __('Medium', 'avenews'), 'entry-image-small' => __('Small', 'avenews'), ), 'std' => 'entry-image-medium', ), 'show_category' => array( 'type' => 'checkbox', 'label' => __('Show Category', 'avenews'), 'std' => false, ), 'has_category_bg' => array( 'type' => 'checkbox', 'label' => __('Category Background Color', '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, ), 'show_share' => array( 'type' => 'checkbox', 'label' => __('Show Share', 'avenews'), 'std' => false, ), ); 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_Carousel_Widget_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()) { echo $args['before_widget']; do_action('avenews_before_carousel_widget'); ?>