0 ) { ?>
widget_cssclass = 'blogmarks_grid_posts_widget'; $this->widget_description = __( 'Displays posts in grid style', 'blogmarks' ); $this->widget_id = 'blogmarks_double_column_posts'; $this->widget_name = __( 'Blogmarks: Grid 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' ), ), ), 'number' => array( 'type' => 'number', 'step' => 1, 'min' => 1, 'max' => '', 'std' => 6, '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' ), ), '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', ), 'image_size' => array( 'type' => 'select', 'std' => 'medium_large', 'label' => __('Featured Image Size', 'blogmarks'), 'options' => array( 'full' => __('Full', 'blogmarks'), '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.', 'blogmarks' ), 'std' => false, ), 'excerpt_settings_heading' => array( 'type' => 'heading', 'label' => __( 'Excerpt Settings', 'blogmarks' ), ), '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_2', ), 'read_more_icon' => array( 'type' => 'select', 'label' => __( 'Read More Icon', 'blogmarks' ), 'options' => blogmarks_get_read_more_icons_list(), 'std' => 'arrow-right', ), 'category_settings_heading' => array( 'type' => 'heading', 'label' => __( 'Category Settings', 'blogmarks' ), ), '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' ), ), 'widget_settings_heading' => array( 'type' => 'heading', 'label' => __( 'Widget Settings', 'blogmarks' ), ), 'no_of_column' => array( 'type' => 'number', 'step' => 1, 'min' => 1, 'max' => 5, 'std' => 2, 'label' => __( 'Number of Column', 'blogmarks' ), ), 'justify_content' => array( 'type' => 'checkbox', 'label' => __( 'Center-align the content', 'blogmarks' ), 'std' => false, ), '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, ), 'hide_image' => array( 'type' => 'checkbox', 'label' => __( 'Hide Image', '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' ) ); } /** * 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']; $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_grid_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_grid_posts' ); $column = isset( $instance['no_of_column'] ) ? $instance['no_of_column'] : $this->settings['no_of_column']['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']; $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']; $show_excerpt = isset( $instance['show_excerpt'] ) ? $instance['show_excerpt'] : $this->settings['show_excerpt']['std']; $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']; $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']; $col_class = 'row row-cols-1 g-4'; if ( 1 == $column ) { $col_class .= ' blogmarks-grid-1'; } elseif ( 2 == $column ) { $col_class .= ' row-cols-sm-2 row-cols-md-2 blogmarks-grid-2'; } elseif ( 3 == $column ) { $col_class .= ' row-cols-md-3 blogmarks-grid-3'; } elseif ( 4 == $column ) { $col_class .= ' row-cols-sm-2 row-cols-xl-4 blogmarks-grid-4'; } elseif ( 5 == $column ) { $col_class .= ' row-cols-sm-2 row-cols-md-3 row-cols-lg-4 row-cols-xl-5 blogmarks-grid-5'; } else { $col_class .= ' row-cols-sm-2 row-cols-lg-2 blogmarks-grid-2'; } // Inverted Color. $widget_class = ''; if ( $inverted_block_color ) { $widget_class .= ' widget-inverted-scheme'; } // Center-align the content. $justify_content = isset( $instance['justify_content'] ) ? $instance['justify_content'] : $this->settings['justify_content']['std']; if ( $justify_content ) { $widget_class .= ' has-text-align-center'; } ?>
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/grid-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 ); } } } }