widget_cssclass = 'widget_blogbyte_popular_posts'; $this->widget_description = __( 'Displays popular posts with an image', 'blogbyte' ); $this->widget_id = 'blogbyte_popular_posts'; $this->widget_name = __( 'Blogbyte: Popular Posts', 'blogbyte' ); $this->settings = array( 'title' => array( 'type' => 'text', 'label' => __( 'Title', 'blogbyte' ), ), 'post_settings_heading' => array( 'type' => 'heading', 'label' => __( 'Post Settings', 'blogbyte' ), ), 'category' => array( 'type' => 'dropdown-taxonomies', 'label' => __( 'Select Category', 'blogbyte' ), 'desc' => __( 'Leave empty if you don\'t want the posts to be category specific', 'blogbyte' ), 'args' => array( 'taxonomy' => 'category', 'class' => 'widefat', 'hierarchical' => true, 'show_count' => 1, 'show_option_all' => __( '— Select —', 'blogbyte' ), ), ), 'no_of_posts' => array( 'type' => 'number', 'step' => 1, 'min' => 1, 'max' => '', 'std' => 5, 'label' => __( 'Number of posts to show', 'blogbyte' ), ), 'offset' => array( 'type' => 'number', 'step' => 1, 'min' => 0, 'max' => '', 'std' => '', 'label' => __( 'Offset', 'blogbyte' ), 'desc' => __( 'Can be useful if you want to skip certain number of posts. Leave as 0 if you do not want to use it.', 'blogbyte' ), ), 'orderby' => array( 'type' => 'select', 'std' => 'date', 'label' => __( 'Order By', 'blogbyte' ), 'options' => array( 'date' => __( 'Date', 'blogbyte' ), 'ID' => __( 'ID', 'blogbyte' ), 'title' => __( 'Title', 'blogbyte' ), 'rand' => __( 'Random', 'blogbyte' ), ), ), 'order' => array( 'type' => 'select', 'std' => 'desc', 'label' => __( 'Order', 'blogbyte' ), 'options' => array( 'asc' => __( 'ASC', 'blogbyte' ), 'desc' => __( 'DESC', 'blogbyte' ), ), ), 'meta_settings_heading' => array( 'type' => 'heading', 'label' => __( 'Post Meta Settings', 'blogbyte' ), ), 'post_meta' => array( 'type' => 'multi-checkbox', 'label' => __( 'Post Meta', 'blogbyte' ), 'options' => array( 'author' => __( 'Author', 'blogbyte' ), 'read_time' => __( 'Post Read Time', 'blogbyte' ), 'date' => __( 'Date', 'blogbyte' ), 'comment' => __( 'Comment', 'blogbyte' ), ), 'std' => array( 'author', 'date' ), ), 'show_meta_on_express_only' => array( 'type' => 'checkbox', 'label' => __( 'Show Post Metas on Express Post Only', 'blogbyte' ), 'desc' => __( 'Make sure to select post meta from above for this to work.', 'blogbyte' ), 'std' => false, ), 'post_meta_icon' => array( 'type' => 'checkbox', 'label' => __( 'Show Post Meta Icon', 'blogbyte' ), 'desc' => __( 'Some Icons may show up regardless to provide better info.', 'blogbyte' ), 'std' => false, ), 'date_format' => array( 'type' => 'select', 'label' => __( 'Date Format', 'blogbyte' ), 'desc' => __( 'Make sure to select Date from above for this to work.', 'blogbyte' ), 'options' => array( 'format_1' => __( 'Times Ago', 'blogbyte' ), 'format_2' => __( 'Default Format', 'blogbyte' ), ), 'std' => 'format_2', ), 'author_image' => array( 'type' => 'checkbox', 'label' => __( 'Show Author Image', 'blogbyte' ), 'desc' => __( 'Make sure to select Author from above for this to work. Will only show up in express post.', 'blogbyte' ), 'std' => false, ), 'category_settings_heading' => array( 'type' => 'heading', 'label' => __( 'Category Settings', 'blogbyte' ), ), 'show_category' => array( 'type' => 'checkbox', 'label' => __( 'Show Category', 'blogbyte' ), 'std' => false, ), 'category_color' => array( 'type' => 'select', 'label' => __( 'Category Color', 'blogbyte' ), 'options' => blogbyte_get_category_color_display(), 'std' => 'none', ), 'category_style' => array( 'type' => 'select', 'label' => __( 'Category Style', 'blogbyte' ), 'options' => blogbyte_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', 'blogbyte' ), ), 'show_cat_on_express_only' => array( 'type' => 'checkbox', 'label' => __( 'Show Categories on Express Post Only', 'blogbyte' ), 'desc' => __( 'Make sure to select Show Category from above for this to work.', 'blogbyte' ), 'std' => false, ), 'widget_settings_heading' => array( 'type' => 'heading', 'label' => __( 'Widget Settings', 'blogbyte' ), ), 'style' => array( 'type' => 'select', 'label' => __( 'Style', 'blogbyte' ), 'options' => array( 'style_1' => __( 'List Only', 'blogbyte' ), 'style_2' => __( 'Express + List', 'blogbyte' ), ), 'std' => 'style_1', ), 'counter_style' => array( 'type' => 'select', 'label' => __( 'Counter Style', 'blogbyte' ), 'options' => array( 'style_1' => __( 'Plain', 'blogbyte' ), 'style_2' => __( 'Plain with a dot', 'blogbyte' ), 'style_3' => __( 'Plain with a border', 'blogbyte' ), 'style_4' => __( 'With Background', 'blogbyte' ), 'style_5' => __( 'With Circular Background', 'blogbyte' ), ), 'std' => 'style_5', ), 'counter_accent_color' => array( 'type' => 'checkbox', 'label' => __( 'Use accent color for the counter', 'blogbyte' ), 'std' => false, ), 'inverted_block_color' => array( 'type' => 'checkbox', 'label' => __( 'Inverted Color', 'blogbyte' ), 'desc' => __( 'Can be used if you have dark background and want lighter color on the text.', 'blogbyte' ), 'std' => false, ), 'title_limit' => array( 'type' => 'select', 'label' => __( 'Post Title Limit', 'blogbyte' ), 'options' => blogbyte_get_title_limit_choices(), 'std' => '', ), 'express_post_display_settings_heading' => array( 'type' => 'message', 'label' => __( 'Express Posts Settings', 'blogbyte' ), ), 'express_counter_style' => array( 'type' => 'select', 'label' => __( 'Express Post Counter Style', 'blogbyte' ), 'desc' => __( 'Useful if you want different counter style on express post.', 'blogbyte' ), 'options' => array( '' => __( '— Inherit —', 'blogbyte' ), 'style_1' => __( 'Plain', 'blogbyte' ), 'style_2' => __( 'Plain with a dot', 'blogbyte' ), 'style_3' => __( 'Plain with a border', 'blogbyte' ), 'style_4' => __( 'With Background', 'blogbyte' ), 'style_5' => __( 'With Circular Background', 'blogbyte' ), ), 'std' => '', ), 'border_below_express_post' => array( 'type' => 'checkbox', 'label' => __( 'Enable Border Below Express Post', 'blogbyte' ), 'std' => false, ), 'invert_express_post' => array( 'type' => 'checkbox', 'label' => __( 'Invert Express Post', 'blogbyte' ), 'std' => false, ), 'bigger_counter_express_post' => array( 'type' => 'checkbox', 'label' => __( 'Increase Counter Font Size on Express Post', 'blogbyte' ), 'std' => false, ), 'list_post_display_settings_heading' => array( 'type' => 'message', 'label' => __( 'List Posts Settings', 'blogbyte' ), ), 'invert_list_post' => array( 'type' => 'checkbox', 'label' => __( 'Invert List Post', 'blogbyte' ), '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( 'blogbyte_popular_posts_query_args', $query_args ) ); } /** * Output widget. * * @see WP_Widget * * @param array $args * @param array $instance */ public function widget( $args, $instance ) { ob_start(); if ( ( $posts = $this->get_posts( $args, $instance ) ) && $posts->have_posts() ) { $this->widget_start( $args, $instance ); do_action( 'blogbyte_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_express_only = isset( $instance['show_cat_on_express_only'] ) ? $instance['show_cat_on_express_only'] : $this->settings['show_cat_on_express_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_express_only = isset( $instance['show_meta_on_express_only'] ) ? $instance['show_meta_on_express_only'] : $this->settings['show_meta_on_express_only']['std']; // Check for list only styles. $list_only_style = false; if ( 'style_1' == $style ) { $list_only_style = true; } $image_size = 'blogbyte-large-img'; $express_post_style = 'style_1'; // Counter Accent Color. if ( $counter_accent_color ) { $widget_class .= ' blogbyte-is-counter-accent'; } // Inverted Color. if ( $inverted_block_color ) { $widget_class .= ' saga-block-inverted-color'; } // Border Below Express Post. $border_below_express_post = isset( $instance['border_below_express_post'] ) ? $instance['border_below_express_post'] : $this->settings['border_below_express_post']['std']; if ( $border_below_express_post ) { $widget_class .= ' blogbyte-border-popular-express'; } // Bigger Counter in Express Post. $bigger_counter_express_post = isset( $instance['bigger_counter_express_post'] ) ? $instance['bigger_counter_express_post'] : $this->settings['bigger_counter_express_post']['std']; if ( $bigger_counter_express_post ) { $widget_class .= ' blogbyte-big-popular-express'; } // Inverted Style. $invert_express_post = isset( $instance['invert_express_post'] ) ? $instance['invert_express_post'] : $this->settings['invert_express_post']['std']; $invert_list_post = isset( $instance['invert_list_post'] ) ? $instance['invert_list_post'] : $this->settings['invert_list_post']['std']; if ( $invert_express_post ) { $widget_class .= ' blogbyte-inverted-popular-express'; } if ( $invert_list_post ) { $widget_class .= ' blogbyte-inverted-popular-list'; } $show_image = false; $is_express_post = false; ?> widget_end( $args ); } echo ob_get_clean(); } public function display_image( $size ) { if ( has_post_thumbnail() ) : ?>
the_title_attribute( array( 'echo' => false, ) ), ) ); ?>

id_base ) ) { $file_prefix = is_rtl() ? '-rtl' : ''; $css_file = get_template_directory() . '/inc/widgets/css/popular-posts' . $file_prefix . '.css'; if ( file_exists( $css_file ) ) { $styles = wp_strip_all_tags( file_get_contents( $css_file ) ); wp_add_inline_style( 'blogbyte-style', $styles ); } } } }