File: /var/www/html/site/newsite/wp-content/themes/ooze/inc/widgets/slider-post-widget.php
<?php
if (!defined('ABSPATH')) {
exit;
}
class Ooze_Slider_Post extends Ooze_Widget_Base
{
/**
* Sets up a new widget instance.
*
* @since 1.0.0
*/
public function __construct()
{
$this->widget_cssclass = 'widget_ooze_slider_posts';
$this->widget_description = __("Displays slider section with an image", 'ooze');
$this->widget_id = 'ooze_slider_posts';
$this->widget_name = __('Ooze: Slider Section', 'ooze');
$this->settings = array(
'title' => array(
'type' => 'text',
'label' => __('Title', 'ooze'),
),
'select_category' => array(
'type' => 'dropdown-taxonomies',
'label' => __('Select Category', 'ooze'),
'desc' => __('Leave empty if you don\'t want the posts to be category specific', 'ooze'),
'args' => array(
'taxonomy' => 'category',
'class' => 'widefat',
'hierarchical' => true,
'show_count' => 1,
'show_option_all' => __('— Select —', 'ooze'),
),
),
'show_categroy' => array(
'type' => 'checkbox',
'label' => __('Show Category', 'ooze'),
'std' => true,
),
'show_author' => array(
'type' => 'checkbox',
'label' => __('Show Author', 'ooze'),
'std' => true,
),
'show_date' => array(
'type' => 'checkbox',
'label' => __('Show Date', 'ooze'),
'std' => true,
),
'date_format' => array(
'type' => 'select',
'label' => __('Date Format', 'ooze'),
'options' => array(
'format_1' => __('Format 1', 'ooze'),
'format_2' => __('Format 2', 'ooze'),
),
'std' => 'format_1',
),
);
parent::__construct();
}
/**
* Output widget.
*
* @param array $args
* @param array $instance
* @see WP_Widget
*
*/
public function widget($args, $instance)
{
ob_start();
$slider_query_args = array(
'posts_per_page' => 5,
'post_status' => 'publish',
'no_found_rows' => 1,
'ignore_sticky_posts' => 1,
);
if (!empty($instance['select_category']) && -1 != $instance['select_category'] && 0 != $instance['select_category']) {
$slider_query_args['tax_query'][] = array(
'taxonomy' => 'category',
'field' => 'term_id',
'terms' => $instance['select_category'],
);
}
$slider_query_args_1 = array(
'posts_per_page' => 1,
'post_status' => 'publish',
'no_found_rows' => 1,
'offset' => 5,
);
if (!empty($instance['select_category']) && -1 != $instance['select_category'] && 0 != $instance['select_category']) {
$slider_query_args_1['tax_query'][] = array(
'taxonomy' => 'category',
'field' => 'term_id',
'terms' => $instance['select_category'],
);
} ?>
<div class="theme-grid-block theme-block">
<div class="wrapper">
<div class="column-row">
<div class="column column-12">
<?php if (!empty($instance['title'])) { ?>
<div class="theme-section-header mb-24">
<h2 class="section-header-title m-0">
<?php echo esc_html($instance['title']); ?> </h2>
</h2>
</div>
<?php } ?>
<div class="theme-section-body">
<div class="column-row column-row-medium">
<div class="column column-8 column-sm-12 sm-mb-16">
<div class="swiper grid-block-slider">
<div class="swiper-wrapper">
<?php
$ooze_slider_post_query = new WP_Query($slider_query_args);
if ($ooze_slider_post_query->have_posts()):
while ($ooze_slider_post_query->have_posts()):
$ooze_slider_post_query->the_post();
$featured_image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large');
$featured_image = isset($featured_image[0]) ? $featured_image[0] : '';?>
<div class="swiper-slide">
<article
class="theme-news-article theme-article-flex article-flex-big no-flex-space container-bg-color xs-article-flex-column">
<?php if ($featured_image) { ?>
<div class="data-bg image-size-medium"
data-background="<?php echo esc_url($featured_image); ?>">
</div>
<?php } ?>
<div class="theme-article-content flex-content-center">
<div class="entry-meta-top mb-4">
<?php if ($instance['show_categroy']) { ?>
<div class="entry-meta">
<?php ooze_post_category(); ?>
</div>
<?php } ?>
</div>
<h2 class="entry-title font-size-medium line-clamp line-clamp-4 mb-16">
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</h2>
<div class="theme-article-excerpt line-clamp line-clamp-3 mb-16">
<?php the_excerpt(); ?>
</div>
<div class="entry-meta-bottom">
<?php if ($instance['show_author']) { ?>
<div class="entry-meta">
<?php ooze_posted_by(); ?>
</div>
<?php } ?>
<?php
if ($instance['show_date']) {
?>
<div class="ooze-meta post-date">
<span class="meta-icon">
<span class="screen-reader-text">
<?php _e('Post Date', 'ooze'); ?>
</span>
<?php ooze_theme_svg('calendar'); ?>
</span>
<span class="meta-text">
<?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', 'ooze'));
} else {
echo esc_html(get_the_date());
}
?>
</span>
</div>
<?php
}
?>
</div>
</div>
</article>
</div>
<?php
endwhile;
endif;
wp_reset_postdata();
?>
</div>
<div class="swiper-pagination swiper-pagination-right"></div>
</div>
</div>
<?php
$ooze_slider_post_query_2 = new WP_Query($slider_query_args_1);
if ($ooze_slider_post_query_2->have_posts()):
while ($ooze_slider_post_query_2->have_posts()):
$ooze_slider_post_query_2->the_post();
$featured_image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large');
$featured_image = isset($featured_image[0]) ? $featured_image[0] : '';?>
<div class="column column-4 column-sm-12">
<article class="theme-news-article article-content-overlay mb-16">
<?php if ($featured_image) { ?>
<div class="data-bg image-size-medium data-bg-overlay"
data-background="<?php echo esc_url($featured_image); ?>">
</div>
<?php } ?>
<div class="theme-article-content">
<?php if ($instance['show_categroy']) { ?>
<div class="entry-meta entry-meta-top mb-8">
<?php ooze_post_category(); ?>
</div>
<?php } ?>
<?php if ($instance['show_author']) { ?>
<div class="entry-meta entry-meta-top mb-8">
<?php ooze_posted_by(); ?>
</div>
<?php } ?>
<h2 class="entry-title font-size-medium line-clamp line-clamp-2 mb-8">
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</h2>
<div class="theme-article-excerpt line-clamp line-clamp-3">
<p> <?php the_excerpt(); ?> </p>
</div>
</div>
</article>
</div>
<?php
endwhile;
endif;
wp_reset_postdata();
?>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
echo ob_get_clean();
}
}