widget_cssclass = 'avenews-widget-recent-grid avenews-fullwidth-widget'; $this->widget_description = __("Displays Recent News in Grid orientation", 'avenews'); $this->widget_id = 'Avenews_Recent_Grid_Widget'; $this->widget_name = __('Avenews: Recent Grid News', '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_of_coll' => array( 'type' => 'select', 'label' => __('Number of Column to Show', 'avenews'), 'options' => array( 'column-6' => __('Column 2', 'avenews'), 'column-4' => __('Column 3', 'avenews'), 'column-3' => __('Column 4', 'avenews'), ), 'std' => 'column-3', ), 'number' => array( 'type' => 'number', 'step' => 1, 'min' => 2, 'max' => 12, 'std' => 4, 'label' => __('Number of posts to show', 'avenews'), ), 'image_size' => array( 'type' => 'select', 'label' => __('Image size', 'avenews'), 'options' => array( 'entry-image-medium' => __('Medium', 'avenews'), 'entry-image-small' => __('Small', 'avenews'), 'entry-image-thumbnail' => __('Thumbnail', 'avenews'), ), 'std' => 'entry-image-small', ), 'display_style' => array( 'type' => 'select', 'label' => __('Display Style', 'avenews'), 'options' => array( 'theme-article-default' => __('Grid Layout', 'avenews'), 'theme-article-list' => __('List Layout', 'avenews'), ), 'std' => 'theme-article-default', ), '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, ), 'bg_color_option' => array( 'type' => 'color', 'label' => __('Background Color', 'avenews'), 'std' => '#ffffff', ), 'text_color_option' => array( 'type' => 'color', 'label' => __('Text Color', 'avenews'), 'std' => '#404040', ), 'margin_bottom_option' => array( 'type' => 'number', 'step' => 10, 'min' => 0, 'max' => 100, 'std' => 0, 'label' => __('Margin Bottom (PX)', 'avenews'), ), 'margin_top_option' => array( 'type' => 'number', 'step' => 10, 'min' => 0, 'max' => 100, 'std' => 0, 'label' => __('Margin Top (PX)', 'avenews'), ), 'padding_bottom_option' => array( 'type' => 'number', 'step' => 10, 'min' => 0, 'max' => 100, 'std' => 0, 'label' => __('Padding Bottom (PX)', 'avenews'), ), 'padding_top_option' => array( 'type' => 'number', 'step' => 10, 'min' => 0, 'max' => 100, 'std' => 0, 'label' => __('Padding Top (PX)', 'avenews'), ), 'bg_image' => array( 'type' => 'image', 'label' => __('Background Image', 'avenews'), 'desc' => __('Don\'t upload any image if you do not want to show the background image.', 'avenews'), ), 'overlay_opacity' => array( 'type' => 'number', 'step' => 10, 'min' => 0, 'max' => 100, 'std' => 50, 'label' => __('Overlay Opacity (Default 50%)', 'avenews'), ), 'bg_overlay_color' => array( 'type' => 'color', 'label' => __('Overlay Background Color', 'avenews'), 'std' => '#000000', ), ); 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'])) { $query_args['tax_query'][] = array( 'taxonomy' => 'category', 'field' => 'term_id', 'terms' => $instance['category'], ); } return new WP_Query(apply_filters('Avenews_Recent_Grid_Widget_query_args', $query_args)); } /** * Output widget. * * @param array $args * @param array $instance * @see WP_Widget */ public function widget($args, $instance) { ob_start(); $class = ''; $image_enabled = !empty($instance['bg_image']); $bg_color_option = isset($instance['bg_color_option']) ? $instance['bg_color_option'] : ''; $style_text = '--recent-grid-color:' . esc_attr($instance['text_color_option']) . ';'; $margin_bottom_option = isset($instance['margin_bottom_option']) ? $instance['margin_bottom_option'] : ''; $margin_top_option = isset($instance['margin_top_option']) ? $instance['margin_top_option'] : ''; $padding_bottom_option = isset($instance['padding_bottom_option']) ? $instance['padding_bottom_option'] : ''; $padding_top_option = isset($instance['padding_top_option']) ? $instance['padding_top_option'] : ''; $style_text .= 'background-color:' . esc_attr($bg_color_option) . ';'; $style_text .= 'margin-bottom:' . esc_attr($margin_bottom_option) . 'px;'; $style_text .= 'margin-top:' . esc_attr($margin_top_option) . 'px;'; $style_text .= 'padding-bottom:' . esc_attr($padding_bottom_option) . 'px;'; $style_text .= 'padding-top:' . esc_attr($padding_top_option) . 'px;'; $style = 'background-color:' . esc_attr($instance['bg_overlay_color']) . ';'; $style .= 'opacity:' . (absint($instance['overlay_opacity']) / 100) . ';'; $class .= esc_attr($instance['display_style']); echo $args['before_widget']; do_action('avenews_before_recent_grid'); ?>
get_posts($args, $instance)) && $posts->have_posts()) { if ($image_enabled && $instance['bg_image'] && wp_get_attachment_url($instance['bg_image'])) { $style = 'background-color:' . esc_attr($instance['bg_overlay_color']) . ';'; $style .= 'opacity:' . (absint($instance['overlay_opacity']) / 100) . ';'; ?> 'avenews-cover-image')); ?>

have_posts()): $posts->the_post(); ?>