widget_cssclass = 'bloglex-multi-grid-post'; $this->widget_description = __("Shows post in multi grid layout", 'bloglex'); $this->widget_id = 'Bloglex_Multi_Grid_Post'; $this->widget_name = __('Bloglex: Multi Grid Post', 'bloglex'); $this->settings = $this->get_widget_settings(); parent::__construct(); } /** * Define widget settings. */ protected function get_widget_settings() { return array( 'title' => array( 'type' => 'text', 'label' => __('Title', 'bloglex'), ), 'title_size_1' => array( 'type' => 'select', 'label' => __('Font size for Prime Article', 'bloglex'), 'options' => array( 'entry-title-medium' => __('Medium', 'bloglex'), 'entry-title-small' => __('Small', 'bloglex'), ), 'std' => 'entry-title-medium', ), 'title_size_2' => array( 'type' => 'select', 'label' => __('Font size for Sub Articles', 'bloglex'), 'options' => array( 'entry-title-medium' => __('Medium', 'bloglex'), 'entry-title-small' => __('Small', 'bloglex'), ), 'std' => 'entry-title-small', ), 'number' => array( 'type' => 'number', 'step' => 1, 'min' => 2, 'max' => 12, 'std' => 5, 'label' => __('Number of posts to show', 'bloglex'), ), 'image_size' => array( 'type' => 'select', 'label' => __('Image size', 'bloglex'), 'options' => array( 'entry-image-large' => __('Large', 'bloglex'), 'entry-image-big' => __('Big', 'bloglex'), 'entry-image-medium' => __('Medium', 'bloglex'), 'entry-image-small' => __('Small', 'bloglex'), ), 'std' => 'entry-image-big', ), 'show_description' => array( 'type' => 'checkbox', 'label' => __('Show Description', 'bloglex'), 'std' => true, ), 'category' => array( 'type' => 'dropdown-taxonomies', 'label' => __('Select Category', 'bloglex'), 'desc' => __('Leave empty if you don\'t want the posts to be category specific', 'bloglex'), 'args' => array( 'taxonomy' => 'category', 'class' => 'widefat', 'hierarchical' => true, 'show_count' => 1, 'show_option_all' => __('— Select —', 'bloglex'), ), ), 'show_category' => array( 'type' => 'checkbox', 'label' => __('Show Category', 'bloglex'), 'std' => true, ), 'category_text' => array( 'type' => 'text', 'label' => __('Category Text', 'bloglex'), ), 'display_category_option' => array( 'type' => 'select', 'label' => __('Category Option', 'bloglex'), 'options' => array( 'none' => __('None', 'bloglex'), 'has-background' => __('Has dot', 'bloglex'), 'has-text-color' => __('Has text color', 'bloglex'), ), 'std' => 'has-text-color', ), 'number_of_cat' => array( 'type' => 'number', 'step' => 1, 'min' => 1, 'std' => 1, 'label' => __('Number of Category to show', 'bloglex'), ), 'show_date' => array( 'type' => 'checkbox', 'label' => __('Show Date', 'bloglex'), 'std' => true, ), 'date_format' => array( 'type' => 'select', 'label' => __('Date Format', 'bloglex'), 'options' => array( 'format_1' => __('Format 1', 'bloglex'), 'format_2' => __('Format 2', 'bloglex'), ), 'std' => 'format_2', ), 'show_author' => array( 'type' => 'checkbox', 'label' => __('Show Author', 'bloglex'), 'std' => true, ), 'display_author_option' => array( 'type' => 'select', 'label' => __('Author Option', 'bloglex'), 'options' => array( 'with_label' => __('With Label', 'bloglex'), 'with_icon' => __('With Icon', 'bloglex'), 'with_avatar_image' => __('With Avatar Image', 'bloglex'), ), 'std' => 'with_icon', ), 'author_text' => array( 'type' => 'text', 'label' => __('Author Text', 'bloglex'), 'std' => __('By:', 'bloglex'), 'desc' => __('This only works when the "With Label" option is selected under "Author Option"', 'bloglex'), ), 'style' => array( 'type' => 'select', 'label' => __('Style', 'bloglex'), 'options' => array( 'style_1' => __('Style 1', 'bloglex'), 'style_2' => __('Style 2', 'bloglex'), ), 'std' => 'style_1', ), ); } /** * 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('Bloglex_Multi_Grid_Post_query_args', $query_args)); } /** * Output widget. * * @param array $args * @param array $instance * @see WP_Widget * */ public function widget($args, $instance) { ob_start(); $count = 1; if (($posts = $this->get_posts($args, $instance)) && $posts->have_posts()) { echo $args['before_widget']; do_action('bloglex_before_simplepost_widget'); ?>