widget_cssclass = 'widget_blogmarks_popular_posts'; $this->widget_description = __('Displays popular posts with an image', 'blogmarks'); $this->widget_id = 'blogmarks_popular_posts'; $this->widget_name = __('Blogmarks: Popular Posts', 'blogmarks'); $this->settings = array( 'title' => array( 'type' => 'text', 'label' => __('Title', 'blogmarks'), ), 'post_settings_heading' => array( 'type' => 'heading', 'label' => __('Post Settings', 'blogmarks'), ), 'category' => array( 'type' => 'dropdown-taxonomies', 'label' => __('Select Category', 'blogmarks'), 'desc' => __('Leave empty if you don\'t want the posts to be category specific', 'blogmarks'), 'args' => array( 'taxonomy' => 'category', 'class' => 'widefat', 'hierarchical' => true, 'show_count' => 1, 'show_option_all' => __('— Select —', 'blogmarks'), ), ), 'no_of_posts' => array( 'type' => 'number', 'step' => 1, 'min' => 1, 'max' => '', 'std' => 5, 'label' => __('Number of posts to show', 'blogmarks'), ), 'offset' => array( 'type' => 'number', 'step' => 1, 'min' => 0, 'max' => '', 'std' => '', 'label' => __('Offset', 'blogmarks'), 'desc' => __('Can be useful if you want to skip certain number of posts. Leave as 0 if you do not want to use it.', 'blogmarks'), ), 'orderby' => array( 'type' => 'select', 'std' => 'date', 'label' => __('Order By', 'blogmarks'), 'options' => array( 'date' => __('Date', 'blogmarks'), 'ID' => __('ID', 'blogmarks'), 'title' => __('Title', 'blogmarks'), 'rand' => __('Random', 'blogmarks'), ), ), 'order' => array( 'type' => 'select', 'std' => 'desc', 'label' => __('Order', 'blogmarks'), 'options' => array( 'asc' => __('ASC', 'blogmarks'), 'desc' => __('DESC', 'blogmarks'), ), ), 'meta_settings_heading' => array( 'type' => 'heading', 'label' => __('Post Meta Settings', 'blogmarks'), ), 'post_meta' => array( 'type' => 'multi-checkbox', 'label' => __('Post Meta', 'blogmarks'), 'options' => array( 'author' => __('Author', 'blogmarks'), 'read_time' => __('Post Read Time', 'blogmarks'), 'date' => __('Date', 'blogmarks'), 'comment' => __('Comment', 'blogmarks'), ), 'std' => array('author', 'date'), ), 'show_meta_on_spotlight_only' => array( 'type' => 'checkbox', 'label' => __('Show Post Metas on Spotlight Post Only', 'blogmarks'), 'desc' => __('Make sure to select post meta from above for this to work.', 'blogmarks'), 'std' => false, ), 'post_meta_icon' => array( 'type' => 'checkbox', 'label' => __('Show Post Meta Icon', 'blogmarks'), 'desc' => __('Some Icons may show up regardless to provide better info.', 'blogmarks'), 'std' => false, ), 'date_format' => array( 'type' => 'select', 'label' => __('Date Format', 'blogmarks'), 'desc' => __('Make sure to select Date from above for this to work.', 'blogmarks'), 'options' => array( 'format_1' => __('Times Ago', 'blogmarks'), 'format_2' => __('Default Format', 'blogmarks'), ), 'std' => 'format_2', ), 'image_size' => array( 'type' => 'select', 'std' => 'large', 'label' => __('Featured Image Size', 'blogmarks'), 'options' => array( 'full' => __('Full', 'blogmarks'), 'large' => __('Large', 'blogmarks'), 'medium_large' => __('Medium Large', 'blogmarks'), 'medium' => __('Medium', 'blogmarks'), ), ), 'author_image' => array( 'type' => 'checkbox', 'label' => __('Show Author Image', 'blogmarks'), 'desc' => __('Make sure to select Author from above for this to work. Will only show up in spotlight post.', 'blogmarks'), 'std' => false, ), 'category_settings_heading' => array( 'type' => 'heading', 'label' => __('Category Settings', 'blogmarks'), ), 'show_category' => array( 'type' => 'checkbox', 'label' => __('Show Category', 'blogmarks'), 'std' => false, ), 'category_color' => array( 'type' => 'select', 'label' => __('Category Color', 'blogmarks'), 'options' => blogmarks_get_category_color_display(), 'std' => 'none', ), 'category_style' => array( 'type' => 'select', 'label' => __('Category Style', 'blogmarks'), 'options' => blogmarks_get_category_styles(), 'std' => 'style_1', ), 'no_of_category' => array( 'type' => 'number', 'step' => 1, 'min' => 0, 'max' => '', 'std' => 1, 'label' => __('Number of Category to Display', 'blogmarks'), ), 'show_cat_on_spotlight_only' => array( 'type' => 'checkbox', 'label' => __('Show Categories on Spotlight Post Only', 'blogmarks'), 'desc' => __('Make sure to select Show Category from above for this to work.', 'blogmarks'), 'std' => false, ), 'widget_settings_heading' => array( 'type' => 'heading', 'label' => __('Widget Settings', 'blogmarks'), ), 'style' => array( 'type' => 'select', 'label' => __('Style', 'blogmarks'), 'options' => array( 'style_1' => __('List Only', 'blogmarks'), 'style_2' => __('Spotlight + List', 'blogmarks'), ), 'std' => 'style_1', ), 'counter_style' => array( 'type' => 'select', 'label' => __('Counter Style', 'blogmarks'), 'options' => array( 'style_1' => __('Plain', 'blogmarks'), 'style_2' => __('Plain with a dot', 'blogmarks'), 'style_3' => __('Plain with a border', 'blogmarks'), 'style_4' => __('With Background', 'blogmarks'), 'style_5' => __('With Circular Background', 'blogmarks'), ), 'std' => 'style_5', ), 'counter_accent_color' => array( 'type' => 'checkbox', 'label' => __('Use accent color for the counter', 'blogmarks'), 'std' => false, ), 'inverted_block_color' => array( 'type' => 'checkbox', 'label' => __('Inverted Color', 'blogmarks'), 'desc' => __('Can be used if you have dark background and want lighter color on the text.', 'blogmarks'), 'std' => false, ), 'title_limit' => array( 'type' => 'select', 'label' => __('Title Line Limit', 'blogmarks'), 'options' => blogmarks_get_title_limit_choices(), 'std' => '', ), 'spotlight_post_display_settings_heading' => array( 'type' => 'message', 'label' => __('Spotlight Posts Settings', 'blogmarks'), ), 'spotlight_counter_style' => array( 'type' => 'select', 'label' => __('Spotlight Post Counter Style', 'blogmarks'), 'desc' => __('Useful if you want different counter style on spotlight post.', 'blogmarks'), 'options' => array( '' => __('— Inherit —', 'blogmarks'), 'style_1' => __('Plain', 'blogmarks'), 'style_2' => __('Plain with a dot', 'blogmarks'), 'style_3' => __('Plain with a border', 'blogmarks'), 'style_4' => __('With Background', 'blogmarks'), 'style_5' => __('With Circular Background', 'blogmarks'), ), 'std' => '', ), 'border_below_spotlight_post' => array( 'type' => 'checkbox', 'label' => __('Enable Border Below Spotlight Post', 'blogmarks'), 'std' => false, ), 'bigger_counter_spotlight_post' => array( 'type' => 'checkbox', 'label' => __('Increase Counter Font Size on Spotlight Post', 'blogmarks'), 'std' => false, ), 'list_post_display_settings_heading' => array( 'type' => 'message', 'label' => __('List Posts Settings', 'blogmarks'), ), 'invert_list_post' => array( 'type' => 'checkbox', 'label' => __('Invert List Post', 'blogmarks'), 'std' => false, ), ); parent::__construct(); add_action('wp_enqueue_scripts', array($this, 'enqueue_assets')); } /** * Query the posts and return them. * * @param array $args * @param array $instance * @return WP_Query */ public function get_posts($args, $instance) { $number = !empty($instance['no_of_posts']) ? absint($instance['no_of_posts']) : $this->settings['no_of_posts']['std']; $orderby = !empty($instance['orderby']) ? sanitize_text_field($instance['orderby']) : $this->settings['orderby']['std']; $order = !empty($instance['order']) ? sanitize_text_field($instance['order']) : $this->settings['order']['std']; $offset = !empty($instance['offset']) ? sanitize_text_field($instance['offset']) : $this->settings['offset']['std']; $query_args = array( 'posts_per_page' => $number, 'post_status' => 'publish', 'no_found_rows' => 1, 'orderby' => $orderby, 'order' => $order, 'ignore_sticky_posts' => 1, ); if ($offset && 0 != $offset) { $query_args['offset'] = absint($offset); } 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('blogmarks_popular_posts_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()) { $this->widget_start($args, $instance); do_action('blogmarks_before_popular_posts_with_image'); $style = isset($instance['style']) ? $instance['style'] : $this->settings['style']['std']; $widget_class = $style; $title_limit = isset($instance['title_limit']) ? $instance['title_limit'] : $this->settings['title_limit']['std']; $counter_accent_color = isset($instance['counter_accent_color']) ? $instance['counter_accent_color'] : $this->settings['counter_accent_color']['std']; $inverted_block_color = isset($instance['inverted_block_color']) ? $instance['inverted_block_color'] : $this->settings['inverted_block_color']['std']; $counter_style = isset($instance['counter_style']) ? $instance['counter_style'] : $this->settings['counter_style']['std']; $show_category = isset($instance['show_category']) ? $instance['show_category'] : $this->settings['show_category']['std']; if ($show_category) { $cat_style = isset($instance['category_style']) ? $instance['category_style'] : $this->settings['category_style']['std']; $color = isset($instance['category_color']) ? $instance['category_color'] : $this->settings['category_color']['std']; $limit = isset($instance['no_of_category']) ? $instance['no_of_category'] : $this->settings['no_of_category']['std']; } $cat_on_spotlight_only = isset($instance['show_cat_on_spotlight_only']) ? $instance['show_cat_on_spotlight_only'] : $this->settings['show_cat_on_spotlight_only']['std']; $enabled_post_meta = isset($instance['post_meta']) ? $instance['post_meta'] : $this->settings['post_meta']['std']; $meta_settings['date_format'] = isset($instance['date_format']) ? $instance['date_format'] : $this->settings['date_format']['std']; $meta_settings['show_icons'] = isset($instance['post_meta_icon']) ? $instance['post_meta_icon'] : $this->settings['post_meta_icon']['std']; $meta_settings['author_image'] = isset($instance['author_image']) ? $instance['author_image'] : $this->settings['author_image']['std']; $meta_on_spotlight_only = isset($instance['show_meta_on_spotlight_only']) ? $instance['show_meta_on_spotlight_only'] : $this->settings['show_meta_on_spotlight_only']['std']; // Check for list only styles. $list_only_style = false; if ('style_1' == $style) { $list_only_style = true; } $image_size = $instance['image_size']; $spotlight_post_style = 'style_1'; // Counter Accent Color. if ($counter_accent_color) { $widget_class .= ' blogmarks-is-counter-accent'; } // Inverted Color. if ($inverted_block_color) { $widget_class .= ' widget-inverted-scheme'; } // Border Below Spotlight Post. $border_below_spotlight_post = isset($instance['border_below_spotlight_post']) ? $instance['border_below_spotlight_post'] : $this->settings['border_below_spotlight_post']['std']; if ($border_below_spotlight_post) { $widget_class .= ' blogmarks-border-popular-spotlight'; } // Bigger Counter in Spotlight Post. $bigger_counter_spotlight_post = isset($instance['bigger_counter_spotlight_post']) ? $instance['bigger_counter_spotlight_post'] : $this->settings['bigger_counter_spotlight_post']['std']; if ($bigger_counter_spotlight_post) { $widget_class .= ' blogmarks-big-popular-spotlight'; } // Inverted Style. $invert_list_post = isset($instance['invert_list_post']) ? $instance['invert_list_post'] : $this->settings['invert_list_post']['std']; if ($invert_list_post) { $widget_class .= ' has-inverted-items'; } $show_image = false; $is_spotlight_post = false; ?>
widget_end($args); } echo ob_get_clean(); } public function display_image($size) { if (has_post_thumbnail()) : ?>