widget_cssclass = 'blogmarks_post_categories_grid_widget'; $this->widget_description = __( 'Displays post categories with image in grid', 'blogmarks' ); $this->widget_id = 'blogmarks_post_categories_grid_widget'; $this->widget_name = __( 'Blogmarks: Categories Grid', 'blogmarks' ); $post_categories = array(); $categories = get_categories( array( 'orderby' => 'name', 'order' => 'ASC', ) ); if ( ! empty( $categories ) ) { foreach ( $categories as $cat ) { $post_categories[ $cat->term_id ] = $cat->name; } } $this->settings = array( 'title' => array( 'type' => 'text', 'label' => __( 'Title', 'blogmarks' ), ), 'categories' => array( 'type' => 'multi-checkbox', 'label' => __( 'Select Categories', 'blogmarks' ), 'options' => $post_categories, ), 'no_of_column' => array( 'type' => 'number', 'step' => 1, 'min' => 1, 'max' => 5, 'std' => 2, 'label' => __( 'Number of Column', 'blogmarks' ), ), 'display_style' => array( 'type' => 'select', 'label' => __( 'Display Style', 'blogmarks' ), 'options' => array( 'style_1' => __( 'Default', 'blogmarks' ), 'style_2' => __( 'Category on Bottom', 'blogmarks' ), 'style_3' => __( 'Category on Center', 'blogmarks' ), 'style_4' => __( 'Small Height', 'blogmarks' ), ), 'std' => 'style_1', ), 'show_post_count' => array( 'type' => 'checkbox', 'label' => __( 'Show Post Count', 'blogmarks' ), 'std' => false, ), 'overlay_color' => array( 'type' => 'color', 'label' => __( 'Overlay Color', 'blogmarks' ), 'std' => '#000000', ), 'overlay_opacity' => array( 'type' => 'number', 'step' => 10, 'min' => 0, 'max' => 100, 'std' => 50, 'label' => __( 'Overlay Opacity', 'blogmarks' ), ), ); parent::__construct(); add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_assets' ) ); } /** * Output widget. * * @see WP_Widget * * @param array $args * @param array $instance */ public function widget( $args, $instance ) { ob_start(); if ( ! empty( $instance['categories'] ) ) { $this->widget_start( $args, $instance ); do_action( 'blogmarks_before_post_cat_grid' ); $column = $instance['no_of_column']; $display_style = $instance['display_style']; $show_post_count = isset( $instance['show_post_count'] ) ? $instance['show_post_count'] : $this->settings['show_post_count']['std']; if ( 'style_4' == $display_style ) { $gap = ' g-2'; } else { $gap = ' g-4'; } $col_class = 'row row-cols-1'; if ( 2 == $column ) { $col_class .= ' row-cols-sm-2'; } elseif ( 3 == $column ) { $col_class .= ' row-cols-md-3'; } elseif ( 4 == $column ) { $col_class .= ' row-cols-sm-2 row-cols-xl-4'; } elseif ( 5 == $column ) { $col_class .= ' row-cols-sm-2 row-cols-md-3 row-cols-lg-4 row-cols-xl-5'; } else { $col_class = ' row row-cols-1'; } $col_class .= $gap; $img_size = 'medium_large'; $wrapper_class = $display_style; if ( $show_post_count ) { $wrapper_class .= ' blogmarks-cat-post-count-active'; } $style_attr = ' style="background-color:value;"'; ?>
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/post-categories-grid' . $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 ); } } } }