OwlCyberSecurity - MANAGER
Edit File: class-multi-column-categories.php
<?php if (!defined('ABSPATH')) { exit; } class Newsvista_Multi_Column_Categories extends Newsvista_Widget_Base { /** * Sets up a new widget instance. * * @since 1.0.0 */ public function __construct() { $this->widget_cssclass = 'newsvista_multi_column_widget'; $this->widget_description = __("Displays Multi colum with multiple category widget", 'newsvista'); $this->widget_id = 'newsvista-multi-column-widget'; $this->widget_name = __('Newsvista: Multi Categories', 'newsvista'); $this->settings = array( 'column_number' => array( 'label' => esc_html__('Define No. of Column:', 'newsvista'), 'desc' => __('Number of column you you choose the number of category with title will be shown.', 'newsvista'), 'type' => 'number', 'css' => 'max-width:60px;', 'std' => 2, 'min' => 1, 'max' => 4, ), 'title_1' => array( 'type' => 'text', 'label' => __('First Column: Title', 'newsvista'), 'std' => __('Multi Categories Post Widget 1', 'newsvista'), ), 'select_category_1' => array( 'type' => 'dropdown-taxonomies', 'label' => __('First Column: Select Category', 'newsvista'), 'desc' => __('If you don\'t wish to specify a category for the posts, please leave this field empty.', 'newsvista'), 'args' => array( 'taxonomy' => 'category', 'class' => 'widefat', 'hierarchical' => true, 'show_count' => 1, 'show_option_all' => __('— Select —', 'newsvista'), ), ), 'title_2' => array( 'type' => 'text', 'label' => __('Second Column: Title', 'newsvista'), 'std' => __('Multi Categories Post Widget 2', 'newsvista'), ), 'select_category_2' => array( 'type' => 'dropdown-taxonomies', 'label' => __('Second Column: Select Category', 'newsvista'), 'desc' => __('If you don\'t wish to specify a category for the posts, please leave this field empty.', 'newsvista'), 'args' => array( 'taxonomy' => 'category', 'class' => 'widefat', 'hierarchical' => true, 'show_count' => 1, 'show_option_all' => __('— Select —', 'newsvista'), ), ), 'title_3' => array( 'type' => 'text', 'label' => __('Second Column: Title', 'newsvista'), 'std' => __('Multi Categories Post Widget 2', 'newsvista'), ), 'select_category_3' => array( 'type' => 'dropdown-taxonomies', 'label' => __('Second Column: Select Category', 'newsvista'), 'desc' => __('If you don\'t wish to specify a category for the posts, please leave this field empty.', 'newsvista'), 'args' => array( 'taxonomy' => 'category', 'class' => 'widefat', 'hierarchical' => true, 'show_count' => 1, 'show_option_all' => __('— Select —', 'newsvista'), ), ), 'title_4' => array( 'type' => 'text', 'label' => __('Second Column: Title', 'newsvista'), 'std' => __('Multi Categories Post Widget 2', 'newsvista'), ), 'select_category_4' => array( 'type' => 'dropdown-taxonomies', 'label' => __('Second Column: Select Category', 'newsvista'), 'desc' => __('If you don\'t wish to specify a category for the posts, please leave this field empty.', 'newsvista'), 'args' => array( 'taxonomy' => 'category', 'class' => 'widefat', 'hierarchical' => true, 'show_count' => 1, 'show_option_all' => __('— Select —', 'newsvista'), ), ), 'show_featured_post' => array( 'type' => 'checkbox', 'label' => __('Disable Featured Post', 'newsvista'), 'std' => false, ), 'show_category' => array( 'type' => 'checkbox', 'label' => __('Show Category', 'newsvista'), 'std' => true, ), 'show_date' => array( 'type' => 'checkbox', 'label' => __('Show Date', 'newsvista'), 'std' => true, ), 'show_excerpt' => array( 'type' => 'checkbox', 'label' => __('Show Excerpt', 'newsvista'), 'std' => false, ), 'date_format' => array( 'type' => 'select', 'label' => __('Date Format', 'newsvista'), 'options' => array( 'format_1' => __('Format 1', 'newsvista'), 'format_2' => __('Format 2', 'newsvista'), ), 'std' => 'format_2', ), 'show_horizontal' => array( 'type' => 'checkbox', 'label' => __('Horizontal Layout', 'newsvista'), 'std' => false, ), 'style' => array( 'type' => 'select', 'label' => __('Style', 'newsvista'), 'options' => array( 'style_1' => __('Style 1', 'newsvista'), 'style_2' => __('Style 2', 'newsvista'), ), 'std' => 'style_1', ), ); parent::__construct(); } /** * Output widget. * * @param array $args * @param array $instance * @see WP_Widget * */ public function widget($args, $instance) { ob_start(); echo $args['before_widget']; do_action('newsvista_before_multi_column_categories'); $column_number = $instance['column_number']; $column_class_hrz = ""; ?> <div class="theme-widget-panel"> <div class="column-row"> <?php for ($i = 1; $i <= $column_number ; $i++) { $multi_column_single_arg = array( 'posts_per_page' => 4, 'post_status' => 'publish', 'no_found_rows' => 1, 'ignore_sticky_posts' => 1, ); if (!empty($instance['select_category_' . $i]) && -1 != $instance['select_category_' . $i] && 0 != $instance['select_category_' . $i]) { $multi_column_single_arg['tax_query'][] = array( 'taxonomy' => 'category', 'field' => 'term_id', 'terms' => $instance['select_category_' . $i] ); } $style = $instance['style']; if ($instance['show_horizontal'] == true) { $column_class_hrz = ' widget-column-horizontal'; } switch($column_number) { case 1: $column_class = 'column-12'; break; case 2: $column_class = 'column-6'; break; case 3: $column_class = 'column-4'; break; case 4: $column_class = 'column-3'; break; default: } ?> <div class="column <?php echo esc_attr($column_class); ?> <?php echo esc_attr($column_class_hrz); ?> column-sm-6 column-xs-12"> <?php if (!empty($instance['title_' . $i])) { ?> <header class="theme-widget-header"> <h2 class="widget-title"><?php echo $instance['title_' . $i]; ?></h2> </header> <?php } ?> <div class="theme-widget-content"> <?php $count = 1; if ($instance['show_featured_post'] == true) { $count = 2; ?> <div class="theme-multi-categories-widget theme-widget-list <?php echo esc_attr($style); ?>"> <?php } $newsvista_multi_column_single_query = new WP_Query($multi_column_single_arg); if ($newsvista_multi_column_single_query->have_posts()): while ($newsvista_multi_column_single_query->have_posts()): $newsvista_multi_column_single_query->the_post(); ?> <?php if ($count == 1) { ?> <div class="theme-multi-categories-widget theme-widget-focus"> <article id="post-<?php the_ID(); ?>" <?php post_class('theme-article-post theme-widget-article article-has-effect article-effect-slide'); ?>> <?php if (has_post_thumbnail()) { ?> <div class="entry-image entry-image-medium"> <a href="<?php the_permalink() ?>" class="entry-image-link"> <?php the_post_thumbnail('medium_large', array( 'alt' => the_title_attribute(array( 'echo' => false, )), )); ?> </a> <?php if (newsvista_get_option('show_lightbox_image')) { ?> <a href="<?php echo esc_url(get_the_post_thumbnail_url()); ?>" class="featured-media-fullscreen" data-glightbox=""> <?php newsvista_theme_svg('fullscreen'); ?> </a> <?php } ?> <?php if ($instance['show_category']) { ?> <div class="entry-meta newsvista-meta newsvista-entry-categories"> <?php the_category( ' ' ); ?> </div> <?php } ?> </div> <?php } ?> <div class="entry-details mt-10"> <?php if ($instance['show_date']) { ?> <div class="entry-meta newsvista-meta newsvista-meta-date mb-10"> <?php $date_format = $instance['date_format']; if ('format_1' == $date_format) { echo esc_html(human_time_diff(get_the_time('U'), current_time('timestamp')) . ' ' . __('ago', 'newsvista')); } else { echo esc_html(get_the_date()); } ?> </div> <?php } ?> <header class="entry-header"> <?php the_title('<h3 class="entry-title entry-title-small"><a href="' . esc_url(get_permalink()) . '" rel="bookmark">', '</a></h3>'); ?> </header> <?php if ($instance['show_excerpt']) { ?> <div class="entry-content"> <?php the_excerpt(); ?> </div> <?php } ?> </div> </article> </div> <div class="theme-multi-categories-widget theme-widget-list <?php echo esc_attr($style); ?>"> <?php $count++; } else { ?> <article id="post-<?php the_ID(); ?>" <?php post_class('theme-article-post theme-widget-article article-has-effect article-effect-zoom theme-list-post'); ?>> <?php if (has_post_thumbnail()) { ?> <div class="entry-image entry-image-thumbnail"> <a href="<?php the_permalink() ?>" class="entry-image-link"> <?php the_post_thumbnail('thumbnail', array( 'alt' => the_title_attribute(array( 'echo' => false, )), )); ?> </a> <?php if (newsvista_get_option('show_lightbox_image')) { ?> <a href="<?php echo esc_url(get_the_post_thumbnail_url()); ?>" class="featured-media-fullscreen" data-glightbox=""> <?php newsvista_theme_svg('fullscreen'); ?> </a> <?php } ?> </div> <?php } ?> <div class="entry-details"> <header class="entry-header mb-10"> <?php the_title('<h3 class="entry-title entry-title-xsmall"><a href="' . esc_url(get_permalink()) . '" rel="bookmark">', '</a></h3>'); ?> </header> <?php if ($instance['show_date']) { ?> <div class="entry-meta newsvista-meta newsvista-meta-date"> <?php $date_format = $instance['date_format']; if ('format_1' == $date_format) { echo esc_html(human_time_diff(get_the_time('U'), current_time('timestamp')) . ' ' . __('ago', 'newsvista')); } else { echo esc_html(get_the_date()); } ?> </div> <?php } ?> </div> </article> <?php if ($newsvista_multi_column_single_query->current_post + 1 == $newsvista_multi_column_single_query->post_count) { ?> </div> <?php } ?> <?php } ?> <?php endwhile; endif; wp_reset_postdata(); ?> </div> </div> <?php } ?> </div> </div> <?php do_action('newsvista_after_multi_column_categories'); echo $args['after_widget']; echo ob_get_clean(); } }