widget_cssclass = 'blogmarks widget_tab_posts'; $this->widget_description = __( 'Displays posts in tab', 'blogmarks' ); $this->widget_id = 'blogmarks_tab_posts'; $this->widget_name = __( 'Blogmarks: Tab Posts', 'blogmarks' ); $this->settings = array( 'popular_post_settings' => array( 'type' => 'heading', 'label' => __( 'Popular Post Settings', 'blogmarks' ), ), 'show_popular_posts' => array( 'type' => 'checkbox', 'label' => __( 'Show Tab', 'blogmarks' ), 'std' => true, ), 'popular_posts_desc' => array( 'type' => 'subtitle', 'label' => __( 'Will display post based on comments count', 'blogmarks' ), ), 'popular_posts_title' => array( 'type' => 'text', 'label' => __( 'Title', 'blogmarks' ), 'std' => __( 'Popular', 'blogmarks' ), 'desc' => __( 'Leave as it is to show default title or leave blank to only show icon', 'blogmarks' ), ), 'show_popular_posts_icon' => array( 'type' => 'checkbox', 'label' => __( 'Show Icon', 'blogmarks' ), 'std' => true, ), 'popular_post_cat' => 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' ), ), ), 'popular_post_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' ), ), 'popular_post_order' => array( 'type' => 'select', 'std' => 'desc', 'label' => __( 'Order', 'blogmarks' ), 'options' => array( 'asc' => __( 'ASC', 'blogmarks' ), 'desc' => __( 'DESC', 'blogmarks' ), ), ), 'hot_post_settings' => array( 'type' => 'heading', 'label' => __( 'Hot Post Settings', 'blogmarks' ), ), 'show_hot_posts' => array( 'type' => 'checkbox', 'label' => __( 'Show Tab', 'blogmarks' ), 'std' => false, ), 'hot_posts_title' => array( 'type' => 'text', 'label' => __( 'Title', 'blogmarks' ), 'std' => __( 'Hot', 'blogmarks' ), 'desc' => __( 'Leave as it is to show default title or leave blank to only show icon', 'blogmarks' ), ), 'show_hot_posts_icon' => array( 'type' => 'checkbox', 'label' => __( 'Show Icon', 'blogmarks' ), 'std' => true, ), 'hot_post_cat' => 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' ), ), ), 'hot_post_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' ), ), 'hot_post_orderby' => array( 'type' => 'select', 'std' => 'date', 'label' => __( 'Order By', 'blogmarks' ), 'options' => array( 'date' => __( 'Date', 'blogmarks' ), 'ID' => __( 'ID', 'blogmarks' ), 'title' => __( 'Title', 'blogmarks' ), 'rand' => __( 'Random', 'blogmarks' ), ), ), 'hot_post_order' => array( 'type' => 'select', 'std' => 'desc', 'label' => __( 'Order', 'blogmarks' ), 'options' => array( 'asc' => __( 'ASC', 'blogmarks' ), 'desc' => __( 'DESC', 'blogmarks' ), ), ), 'latest_post_settings' => array( 'type' => 'heading', 'label' => __( 'Latest Post Settings', 'blogmarks' ), ), 'show_latest_posts' => array( 'type' => 'checkbox', 'label' => __( 'Show Tab', 'blogmarks' ), 'std' => true, ), 'latest_posts_title' => array( 'type' => 'text', 'label' => __( 'Title', 'blogmarks' ), 'std' => __( 'Latest', 'blogmarks' ), 'desc' => __( 'Leave as it is to show default title or leave blank to only show icon', 'blogmarks' ), ), 'show_latest_posts_icon' => array( 'type' => 'checkbox', 'label' => __( 'Show Icon', 'blogmarks' ), 'std' => true, ), 'latest_post_cat' => 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' ), ), ), 'latest_post_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' ), ), 'latest_post_orderby' => array( 'type' => 'select', 'std' => 'date', 'label' => __( 'Order By', 'blogmarks' ), 'options' => array( 'date' => __( 'Date', 'blogmarks' ), 'ID' => __( 'ID', 'blogmarks' ), 'title' => __( 'Title', 'blogmarks' ), 'rand' => __( 'Random', 'blogmarks' ), ), ), 'latest_post_order' => array( 'type' => 'select', 'std' => 'desc', 'label' => __( 'Order', 'blogmarks' ), 'options' => array( 'asc' => __( 'ASC', 'blogmarks' ), 'desc' => __( 'DESC', 'blogmarks' ), ), ), 'comments_settings' => array( 'type' => 'heading', 'label' => __( 'Comments Settings', 'blogmarks' ), ), 'show_comment_tab' => array( 'type' => 'checkbox', 'label' => __( 'Show Tab', 'blogmarks' ), 'std' => true, ), 'comments_title' => array( 'type' => 'text', 'label' => __( 'Title', 'blogmarks' ), 'std' => __( 'Comments', 'blogmarks' ), 'desc' => __( 'Leave as it is to show default title or leave blank to only show icon', 'blogmarks' ), ), 'show_comments_icon' => array( 'type' => 'checkbox', 'label' => __( 'Show Icon', 'blogmarks' ), 'std' => true, ), 'comments_number' => array( 'type' => 'number', 'step' => 1, 'min' => 1, 'max' => '', 'std' => 5, 'label' => __( 'Number of comments to show', 'blogmarks' ), ), 'show_comment_user_img' => array( 'type' => 'checkbox', 'label' => __( 'Show Comment Avatar', 'blogmarks' ), 'std' => true, ), 'show_comment_date' => array( 'type' => 'checkbox', 'label' => __( 'Show Comment Date', 'blogmarks' ), 'std' => true, ), 'show_comment_excerpt' => array( 'type' => 'checkbox', 'label' => __( 'Show Comment Excerpt', 'blogmarks' ), 'std' => true, ), 'general_settings' => array( 'type' => 'heading', 'label' => __( 'General Settings', 'blogmarks' ), ), 'number' => array( 'type' => 'number', 'step' => 1, 'min' => 1, 'max' => '', 'std' => 3, 'label' => __( 'Number of posts to show', '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' ), ), '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_1', ), 'author_image' => array( 'type' => 'checkbox', 'label' => __( 'Show Author Image', 'blogmarks' ), 'desc' => __( 'Make sure to select Author from above for this to work.', 'blogmarks' ), 'std' => false, ), 'show_category' => array( 'type' => 'checkbox', 'label' => __( 'Show Category', 'blogmarks' ), 'std' => true, ), 'category_color' => array( 'type' => 'select', 'label' => __( 'Category Color', 'blogmarks' ), 'options' => blogmarks_get_category_color_display(), 'std' => 'as_bg', ), 'category_style' => array( 'type' => 'select', 'label' => __( 'Category Style', 'blogmarks' ), 'options' => blogmarks_get_category_styles(), 'std' => 'style_2', ), 'no_of_category' => array( 'type' => 'number', 'step' => 1, 'min' => 0, 'max' => '', 'std' => 1, 'label' => __( 'Number of Category to Display', 'blogmarks' ), ), 'tab_display_style' => array( 'type' => 'select', 'label' => __( 'Tab Display Style', 'blogmarks' ), 'options' => array( 'style_1' => __( 'Left Image + Right Content', 'blogmarks' ), 'style_2' => __( 'Top Image + Bottom Content', 'blogmarks' ), 'style_3' => __( 'Top Image + Bottom Content Variation', 'blogmarks' ), ), 'std' => 'style_1', ), 'invert_post' => array( 'type' => 'checkbox', 'label' => __( 'Invert Post', '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, ), 'hide_image' => array( 'type' => 'checkbox', 'label' => __( 'Hide Post Image', 'blogmarks' ), 'std' => false, ), 'enable_post_format_icon' => array( 'type' => 'checkbox', 'label' => __( 'Enable Post Format Icon', 'blogmarks' ), 'std' => false, ), 'title_limit' => array( 'type' => 'select', 'label' => __( 'Title Line Limit', 'blogmarks' ), 'options' => blogmarks_get_title_limit_choices(), 'std' => '', ), ); parent::__construct(); add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_assets' ) ); } /** * Outputs the tab Content * * @param array $instance * @param string $block The block to display. */ public function render_tab_title( $instance, $block, $is_active = false ) { if ( ! $block ) { return; } $enabled = isset( $instance[ "show_{$block}_posts" ] ) ? $instance[ "show_{$block}_posts" ] : $this->settings[ "show_{$block}_posts" ]['std']; if ( $enabled ) : $icon = isset( $instance[ "show_{$block}_posts_icon" ] ) ? $instance[ "show_{$block}_posts_icon" ] : $this->settings[ "show_{$block}_posts_icon" ]['std']; $title = isset( $instance[ "{$block}_posts_title" ] ) ? $instance[ "{$block}_posts_title" ] : $this->settings[ "{$block}_posts_title" ]['std']; ?> settings[ "show_{$block}_posts" ]['std']; $hide_image = isset( $instance['hide_image'] ) ? $instance['hide_image'] : $this->settings['hide_image']['std']; $title_limit = isset( $instance['title_limit'] ) ? $instance['title_limit'] : $this->settings['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']; if ( $enabled ) : $number = ! empty( $instance['number'] ) ? absint( $instance['number'] ) : $this->settings['number']['std']; if ( 'popular' == $block ) { $orderby = 'comment_count'; } else { $orderby = ! empty( $instance[ "{$block}_post_orderby" ] ) ? sanitize_text_field( $instance[ "{$block}_post_orderby" ] ) : $this->settings[ "{$block}_post_orderby" ]['std']; } $order = ! empty( $instance[ "{$block}_post_order" ] ) ? sanitize_text_field( $instance[ "{$block}_post_order" ] ) : $this->settings[ "{$block}_post_order" ]['std']; $offset = ! empty( $instance[ "{$block}_post_offset" ] ) ? sanitize_text_field( $instance[ "{$block}_post_offset" ] ) : $this->settings[ "{$block}_post_offset" ]['std']; $query_args = array( 'post_type' => 'post', '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[ "{$block}_post_cat" ] ) && -1 != $instance[ "{$block}_post_cat" ] && 0 != $instance[ "{$block}_post_cat" ] ) { $query_args['tax_query'][] = array( 'taxonomy' => 'category', 'field' => 'term_id', 'terms' => $instance[ "{$block}_post_cat" ], ); } $posts = new WP_Query( $query_args ); if ( $posts->have_posts() ) : $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['author_image'] = isset( $instance['author_image'] ) ? $instance['author_image'] : $this->settings['author_image']['std']; $meta_settings['show_icons'] = isset( $instance['post_meta_icon'] ) ? $instance['post_meta_icon'] : $this->settings['post_meta_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']; } ?>
display_style = isset( $instance['tab_display_style'] ) ? $instance['tab_display_style'] : $this->settings['tab_display_style']['std']; $invert_post = isset( $instance['invert_post'] ) ? $instance['invert_post'] : $this->settings['invert_post']['std']; $inverted_block_color = isset( $instance['inverted_block_color'] ) ? $instance['inverted_block_color'] : $this->settings['inverted_block_color']['std']; $hide_image = isset( $instance['hide_image'] ) ? $instance['hide_image'] : $this->settings['hide_image']['std']; $widget_class = $this->display_style; if ( $invert_post ) { $widget_class .= ' has-inverted-items'; } if ( $hide_image ) { $widget_class .= ' wpintf-hidden-post-image'; } // Comments Tab. if ( function_exists( 'has_blocks' ) ) { $is_gutenberg = true; } else { $is_gutenberg = false; } $show_comment_tab = isset( $instance['show_comment_tab'] ) ? $instance['show_comment_tab'] : $this->settings['show_comment_tab']['std']; // Inverted Color. if ( $inverted_block_color ) { $widget_class .= ' widget-inverted-scheme'; } ++self::$counter; $this->unique_id = 'blogmarks-tab-' . self::$counter; ?> id_base ) ) { $file_prefix = is_rtl() ? '-rtl' : ''; $css_file = get_template_directory() . '/include/widgets/assets/tab-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 ); } } } }