widget_cssclass = 'avenews-widget-tab'; $this->widget_description = __("Displays Tab Widget", 'avenews'); $this->widget_id = 'avenews_tab_posts'; $this->widget_name = __('Avenews: Tab Posts', 'avenews'); $this->settings = array( 'category_1_heading' => array( 'label' => esc_html__('Category 1', 'avenews'), 'type' => 'heading', ), 'cat_1_title' => array( 'type' => 'text', 'label' => __('Title', 'avenews'), ), 'cat_1_number' => array( 'label' => esc_html__('No. of Posts:', 'avenews'), 'type' => 'number', 'css' => 'max-width:60px;', 'std' => 5, 'min' => 1, 'max' => 10, ), 'select_categroy_1' => 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'), ), ), 'category_2_heading' => array( 'label' => esc_html__('Category 2', 'avenews'), 'type' => 'heading', ), 'cat_2_title' => array( 'type' => 'text', 'label' => __('Title', 'avenews'), ), 'cat_2_number' => array( 'label' => esc_html__('No. of Posts:', 'avenews'), 'type' => 'number', 'css' => 'max-width:60px;', 'std' => 5, 'min' => 1, 'max' => 10, ), 'select_categroy_2' => 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'), ), ), 'cat_3_heading' => array( 'label' => esc_html__('Category 3', 'avenews'), 'type' => 'heading', ), 'cat_3_title' => array( 'type' => 'text', 'label' => __('Title', 'avenews'), ), 'cat_3_number' => array( 'label' => esc_html__('No. of post:', 'avenews'), 'type' => 'number', 'css' => 'max-width:60px;', 'std' => 5, 'min' => 1, 'max' => 10, ), 'select_categroy_3' => 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'), ), ), 'show_date' => array( 'type' => 'checkbox', 'label' => __('Show Date', 'avenews'), 'std' => true, ), 'style' => array( 'type' => 'select', 'label' => __('Style', 'avenews'), 'options' => array( 'style_1' => __('Style 1', 'avenews'), 'style_2' => __('Style 2', 'avenews'), ), 'std' => 'style_1', ), 'show_featured_image' => array( 'type' => 'checkbox', 'label' => __('Show Featured Image', 'avenews'), 'std' => true, ), ); parent::__construct(); } /** * Outputs the content for the current widget instance. * * @param array $args Display arguments. * @param array $instance Settings for the current widget instance. * @since 1.0.0 * */ function widget($args, $instance) { echo $args['before_widget']; ?>
$instance['cat_1_number'], 'post_status' => 'publish', 'no_found_rows' => 1, 'ignore_sticky_posts' => 1, ); if (!empty($instance['select_categroy_1']) && -1 != $instance['select_categroy_1'] && 0 != $instance['select_categroy_1']) { $qargs['tax_query'][] = array( 'taxonomy' => 'category', 'field' => 'term_id', 'terms' => $instance['select_categroy_1'], ); } break; case 'cat-2': $qargs = array( 'posts_per_page' => $instance['cat_2_number'], 'post_status' => 'publish', 'no_found_rows' => 1, 'ignore_sticky_posts' => 1, ); if (!empty($instance['select_categroy_2']) && -1 != $instance['select_categroy_2'] && 0 != $instance['select_categroy_2']) { $qargs['tax_query'][] = array( 'taxonomy' => 'category', 'field' => 'term_id', 'terms' => $instance['select_categroy_2'], ); } break; case 'cat-3': $qargs = array( 'posts_per_page' => $instance['cat_3_number'], 'post_status' => 'publish', 'no_found_rows' => 1, 'ignore_sticky_posts' => 1, ); if (!empty($instance['select_categroy_3']) && -1 != $instance['select_categroy_3'] && 0 != $instance['select_categroy_3']) { $qargs['tax_query'][] = array( 'taxonomy' => 'category', 'field' => 'term_id', 'terms' => $instance['select_categroy_3'], ); } break; default: break; } $tab_posts_query = new WP_Query($qargs); $style = $instance['style']; $show_featured_image = $instance['show_featured_image']; if ($tab_posts_query->have_posts()): ?>