widget_cssclass = 'blogmarks_list_posts_widget'; $this->widget_description = __( 'Displays posts in list style', 'blogmarks' ); $this->widget_id = 'blogmarks_spotlight_posts'; $this->widget_name = __( 'Blogmarks: List 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', 'comment' ), ), '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' => true, ), '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' => 'medium_large', 'label' => __('Featured Image Size', 'blogmarks'), 'options' => array( 'large' => __('Large', 'blogmarks'), 'medium_large' => __('Medium Large', 'blogmarks'), 'medium' => __('Medium', 'blogmarks'), 'small' => __('Small', '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' => __( 'Display Style', 'blogmarks' ), 'options' => array( 'style_1' => __( 'Left Spotlight + Right List', 'blogmarks' ), 'style_3' => __( 'Left Spotlight + 2 Columns Right List', 'blogmarks' ), 'style_4' => __( 'Left List + Center Spotlight + Right List', 'blogmarks' ), 'style_5' => __( 'Left List + Center Spotlight + Inverted Right List', 'blogmarks' ), 'style_2' => __( 'Top Spotlight + Bottom List', 'blogmarks' ), 'style_7' => __( 'Top Spotlight + Bottom List Variation', 'blogmarks' ), 'style_9' => __( 'Top Spotlight + Bottom 2 Columns List', 'blogmarks' ), 'style_8' => __( '1 Column List', 'blogmarks' ), 'style_10' => __( '2 Columns List', 'blogmarks' ), 'style_11' => __( '3 Columns List', 'blogmarks' ), 'style_6' => __( '4 Columns List', 'blogmarks' ), ), 'std' => 'style_1', ), 'enable_post_format_icon' => array( 'type' => 'checkbox', 'label' => __( 'Enable Post Format Icon', '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, ), 'spotlight_post_display_settings_heading' => array( 'type' => 'message', 'label' => __( 'Spotlight Posts Settings', 'blogmarks' ), ), 'spotlight_post_style' => array( 'type' => 'select', 'label' => __( 'Spotlight Post Style', 'blogmarks' ), 'options' => array( 'style_1' => __( 'Style 1', 'blogmarks' ), 'style_2' => __( 'Style 2', 'blogmarks' ), ), 'std' => 'style_1', ), 'spotlight_posts_title_limit' => array( 'type' => 'select', 'label' => __( 'Spotlight Title Line Limit', 'blogmarks' ), 'options' => blogmarks_get_title_limit_choices(), 'std' => '', ), 'show_excerpt' => array( 'type' => 'checkbox', 'label' => __( 'Show Excerpt', 'blogmarks' ), 'std' => true, ), 'excerpt_length' => array( 'type' => 'number', 'step' => 1, 'min' => 0, 'max' => '', 'std' => 20, 'label' => __( 'Excerpt Length', 'blogmarks' ), ), 'show_read_more' => array( 'type' => 'checkbox', 'label' => __( 'Show Read More', 'blogmarks' ), 'std' => false, ), 'read_more_text' => array( 'type' => 'text', 'label' => __( 'Read More Text', 'blogmarks' ), 'desc' => __( 'Leave Empty if you want to use default text "Read More" ', 'blogmarks' ), ), 'read_more_style' => array( 'type' => 'select', 'label' => __( 'Read More Style', 'blogmarks' ), 'options' => blogmarks_get_read_more_styles(), 'std' => 'style_1', ), 'read_more_icon' => array( 'type' => 'select', 'label' => __( 'Read More Icon', 'blogmarks' ), 'options' => blogmarks_get_read_more_icons_list(), 'std' => '', ), '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, ), 'circle_list_image' => array( 'type' => 'checkbox', 'label' => __( 'Circle Style List Post Image', 'blogmarks' ), 'std' => false, ), 'hide_list_image' => array( 'type' => 'checkbox', 'label' => __( 'Hide List Post Image', 'blogmarks' ), 'std' => false, ), 'list_posts_title_limit' => array( 'type' => 'select', 'label' => __( 'List Title Line Limit', 'blogmarks' ), 'options' => blogmarks_get_title_limit_choices(), 'std' => '', ), 'enable_list_item_separator' => array( 'type' => 'checkbox', 'label' => __( 'Enable List Item Separator', '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_list_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( 'blogmarks_before_list_posts' ); $style = isset( $instance['style'] ) ? $instance['style'] : $this->settings['style']['std']; $invert_list_post = isset( $instance['invert_list_post'] ) ? $instance['invert_list_post'] : $this->settings['invert_list_post']['std']; $hide_list_image = isset( $instance['hide_list_image'] ) ? $instance['hide_list_image'] : $this->settings['hide_list_image']['std']; $circle_list_image = isset( $instance['circle_list_image'] ) ? $instance['circle_list_image'] : $this->settings['circle_list_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']; $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']; $spotlight_posts_title_limit = isset( $instance['spotlight_posts_title_limit'] ) ? $instance['spotlight_posts_title_limit'] : $this->settings['spotlight_posts_title_limit']['std']; $list_posts_title_limit = isset( $instance['list_posts_title_limit'] ) ? $instance['list_posts_title_limit'] : $this->settings['list_posts_title_limit']['std']; $enable_post_format_icon = isset( $instance['enable_post_format_icon'] ) ? $instance['enable_post_format_icon'] : $this->settings['enable_post_format_icon']['std']; $inverted_block_color = isset( $instance['inverted_block_color'] ) ? $instance['inverted_block_color'] : $this->settings['inverted_block_color']['std']; $spotlight_post_style = isset( $instance['spotlight_post_style'] ) ? $instance['spotlight_post_style'] : $this->settings['spotlight_post_style']['std']; $show_excerpt = isset( $instance['show_excerpt'] ) ? $instance['show_excerpt'] : $this->settings['show_excerpt']['std']; if ( $show_excerpt ) { $excerpt_length = isset( $instance['excerpt_length'] ) ? $instance['excerpt_length'] : $this->settings['excerpt_length']['std']; } $show_read_more = isset( $instance['show_read_more'] ) ? $instance['show_read_more'] : $this->settings['show_read_more']['std']; if ( $show_read_more ) { $read_more_text = isset( $instance['read_more_text'] ) ? $instance['read_more_text'] : ''; $read_more_style = isset( $instance['read_more_style'] ) ? $instance['read_more_style'] : $this->settings['read_more_style']['std']; $read_more_icon = isset( $instance['read_more_icon'] ) ? $instance['read_more_icon'] : $this->settings['read_more_icon']['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']; } $enabled_post_meta = isset( $instance['post_meta'] ) ? $instance['post_meta'] : $this->settings['post_meta']['std']; $date_format = isset( $instance['date_format'] ) ? $instance['date_format'] : $this->settings['date_format']['std']; $post_meta_icon = isset( $instance['post_meta_icon'] ) ? $instance['post_meta_icon'] : $this->settings['post_meta_icon']['std']; $list_item_separator = isset( $instance['enable_list_item_separator'] ) ? $instance['enable_list_item_separator'] : $this->settings['enable_list_item_separator']['std']; $widget_class = $style; if ( $invert_list_post ) { $widget_class .= ' has-inverted-items'; } if ( $hide_list_image ) { $widget_class .= ' wpintf-hidden-post-image'; } if ( $circle_list_image ) { $widget_class .= ' wpintf-circle-list-post-image'; } $counter = 1; $show_image = true; $total_posts = $posts->post_count; $mid_point = floor( $total_posts / 2 ); $mid_point_w_spotlight = $mid_point + 1; switch ( $style ) { case 'style_1': $row_cols_class = ' row-cols-md-2'; break; case 'style_4': case 'style_5': $row_cols_class = ' row-cols-lg-3'; break; case 'style_6': $row_cols_class = ' row-cols-md-2 row-cols-lg-3 row-cols-xl-4'; break; case 'style_10': $row_cols_class = ' row-cols-md-2'; break; case 'style_11': $row_cols_class = ' row-cols-md-2 row-cols-lg-3'; break; default: $row_cols_class = ''; } // Check for list only styles. $list_only_style = false; if ( 'style_6' == $style || 'style_8' == $style || 'style_10' == $style || 'style_11' == $style ) { $list_only_style = true; } $spotlight_cols_class = $list_cols_class = ''; if ( 'style_3' == $style ) { $spotlight_cols_class = '-lg-4'; $list_cols_class = '-lg-8'; } if ( 'style_7' == $style ) { $list_post_image_size = 'large'; } else { $list_post_image_size = $instance['image_size']; } // List Item Separator. if ( $list_item_separator ) { $widget_class .= ' wpintf-item-sep'; } // Inverted Color. if ( $inverted_block_color ) { $widget_class .= ' widget-inverted-scheme'; } ?>
have_posts() ) : $posts->the_post(); $wrapper_class_start = $wrapper_class_end = $article_wrapper_start = $article_wrapper_end = ''; if ( ! $list_only_style ) { if ( 1 == $counter ) { $wrapper_class_start = '
'; $wrapper_class_end = '
'; $image_size = 'large'; } else { $image_size = $list_post_image_size; if ( 2 == $counter ) { $wrapper_class_start = '
'; } if ( 'style_3' == $style || 'style_9' == $style ) { if ( 2 == $counter || ( $counter % 2 ) == 0 ) { $article_wrapper_start = '
'; } if ( $total_posts == $counter || ( $counter % 2 ) == 1 ) { $article_wrapper_end = '
'; } } // Close the list post div at midpoint and open it up on the next post after midpoint. if ( 'style_4' == $style || 'style_5' == $style ) { if ( $counter == $mid_point_w_spotlight ) { $wrapper_class_end = '
'; } if ( $counter == ( $mid_point_w_spotlight + 1 ) ) { $wrapper_class_start = '
'; } } // Make sure to close on the last post. if ( $counter == $total_posts ) { $wrapper_class_end = '
'; } } } else { $image_size = $list_post_image_size; $wrapper_class_start = '
'; $wrapper_class_end = '
'; } if ( $hide_list_image ) { if ( 1 != $counter || $list_only_style ) { $show_image = false; } else { $show_image = true; } } ?>
>
the_title_attribute( array( 'echo' => false, ) ), ) ); ?>
'; blogmarks_post_categories($cat_style, $color, $limit); echo '
'; } } else { echo '
'; blogmarks_post_categories($cat_style, $color, $limit); echo '
'; } } ?>

settings['author_image']['std']; } else { $meta_settings['author_image'] = false; } if ($meta_on_spotlight_only) { if (1 == $counter && (!$list_only_style)) { blogmarks_post_meta_info($enabled_post_meta, $meta_settings); } } else { blogmarks_post_meta_info($enabled_post_meta, $meta_settings); } ?> 0) : ?>

0) : ?>

widget_end( $args ); } echo ob_get_clean(); } public function enqueue_assets() { if ( is_active_widget( false, false, $this->id_base ) ) { $file_prefix = is_rtl() ? '-rtl' : ''; $css_file = get_template_directory() . '/include/widgets/assets/list-posts' . $file_prefix . '.css'; if ( file_exists( $css_file ) ) { $styles = wp_strip_all_tags( file_get_contents( $css_file ) ); wp_add_inline_style( 'blogmarks-style', $styles ); } } } }