File: /var/www/html/site/newsite/wp-content/themes/ooze/inc/widgets/grid-post-widget.php
<?php
if (!defined('ABSPATH')) {
exit;
}
class Ooze_Grid_Post extends Ooze_Widget_Base
{
/**
* Sets up a new widget instance.
*
* @since 1.0.0
*/
public function __construct()
{
$this->widget_cssclass = 'widget_ooze_grid_posts';
$this->widget_description = __("Displays grid section with an image", 'ooze');
$this->widget_id = 'ooze_grid_posts';
$this->widget_name = __('Ooze: Grid 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();
$grid_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']) {
$grid_query_args['tax_query'][] = array(
'taxonomy' => 'category',
'field' => 'term_id',
'terms' => $instance['select_category'],
);
}
?>
<div class="theme-main-banner theme-block">
<div class="wrapper">
<?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="column-row column-row-medium">
<?php
$count = 1;
$ooze_grid_post_query = new WP_Query($grid_query_args);
if ($ooze_grid_post_query->have_posts()):
while ($ooze_grid_post_query->have_posts()):
$ooze_grid_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] : '';?>
<?php if ($count == 1) { ?>
<div class="column column-5">
<article class="theme-news-article article-content-overlay mb-16">
<?php if ($featured_image) { ?>
<div class="data-bg image-size-big 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">
<?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 } ?>
<?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
}
?>
<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>
<div class="column column-7">
<div class="column-row column-row-medium">
<?php $count++; } else { ?>
<div class="column column-6">
<article class="theme-news-article article-content-overlay mb-16">
<?php if ($featured_image) { ?>
<div class="data-bg image-size-small 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">
<?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 } ?>
<?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
}
?>
<h2 class="entry-title font-size-small line-clamp line-clamp-2 mb-8">
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</h2>
</div>
</article>
</div>
<?php if ($ooze_grid_post_query->current_post +1 == $ooze_grid_post_query->post_count) { ?>
</div>
</div>
<?php } ?>
<?php } ?>
<?php
endwhile;
endif;
wp_reset_postdata();
?>
</div>
</div>
</div>
<?php
echo ob_get_clean();
}
}