widget_cssclass = 'avenews-widget-simple-post'; $this->widget_description = __("Displays featured posts with an image on simple post", 'avenews'); $this->widget_id = 'Avenews_Simple_Post_Widget'; $this->widget_name = __('Avenews: Simple Post Widget', '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'), ), '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, ), ); 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_Simple_Post_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_simplepost_widget'); ?>