File: /var/www/cardquest.pl/del/wp-content/plugins0/disto-function/widget/recent-grid.php
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
add_action( 'widgets_init', 'disto_recent_post_grid_widgets' );
function disto_recent_post_grid_widgets() {
register_widget( 'disto_recent_post_grid_widget' );
}
class disto_recent_post_grid_widget extends WP_Widget {
/*-----------------------------------------------------------------------------------*/
/* Widget Setup
/*-----------------------------------------------------------------------------------*/
public function __construct() {
$widget_ops = array(
'classname' => 'post_grid_widget',
'description' => esc_html__('Display grid of recent post.', 'disto')
);
parent::__construct('disto_recent_post_grid_widget', esc_html__('jellywp: Recently grid Posts', 'disto'), $widget_ops);
}
/*-----------------------------------------------------------------------------------*/
/* Display Widget
/*-----------------------------------------------------------------------------------*/
function widget($args, $instance) {
extract($args);
$cats = isset($instance["cats"]) ? $instance["cats"] : "";
$title = isset($instance['title']) ? esc_attr($instance['title']) : 'Recent Posts';
$number = isset($instance['number']) ? absint($instance['number']) : 4;
$number_offset = isset($instance['number_offset']) ? absint($instance['number_offset']) : 0;
$post_cat_args = array(
'showposts' => $number,
'category__in' => $cats,
'ignore_sticky_posts' => 1,
'offset' => $number_offset
);
$post_cat_widget = null;
$post_cat_widget = new WP_Query($post_cat_args);
print '<span class="jl_none_space"></span>'.$before_widget;
print '<span class="jl_none_space"></span>'.$before_title;
print esc_attr($title);
print '<span class="jl_none_space"></span>'.$after_title;
// Post list in widget
print '<div class="recent-grid-post-widget">';
$grid_i=0;
while ($post_cat_widget->have_posts()) {
$post_cat_widget->the_post();
$post_id = get_the_ID();
$grid_i++;
?>
<div class="grid_post_wrapper<?php if($grid_i %2==0){echo " last_grid ";}?>">
<a href="<?php the_permalink(); ?>" class="recent-grid-post featured-thumbnail" title="<?php the_title_attribute(); ?>">
<?php if ( has_post_thumbnail()) {the_post_thumbnail('disto_slider_grid_small');}
else{} ?>
<div class="background_over_image"></div>
</a>
<div class="item-details">
<h3 class="feature-post-title"><a href="<?php the_permalink(); ?>">
<?php the_title()?></a></h3>
</div>
</div>
<?php if($grid_i %2==0){echo "<div class='clear_div'></div>";}?>
<?php
}
wp_reset_postdata();
print "</div>";
print '<span class="jl_none_space"></span>'.$after_widget;
}
/*-----------------------------------------------------------------------------------*/
/* Update Widget
/*-----------------------------------------------------------------------------------*/
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['cats'] = $new_instance['cats'];
$instance['number'] = absint($new_instance['number']);
$instance['number_offset'] = absint($new_instance['number_offset']);
return $instance;
}
/*-----------------------------------------------------------------------------------*/
/* Widget Settings (Displays the widget settings controls on the widget panel)
/*-----------------------------------------------------------------------------------*/
function form( $instance ) {
$title = isset($instance['title']) ? esc_attr($instance['title']) : 'Recent Posts';
$number = isset($instance['number']) ? absint($instance['number']) : 4;
$number_offset = isset($instance['number_offset']) ? absint($instance['number_offset']) : 0;
?>
<p><label for="<?php echo esc_attr($this->get_field_id('title')); ?>">
<?php esc_html_e('Title:', 'disto'); ?></label>
<input class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?>" name="<?php echo esc_attr($this->get_field_name('title')); ?>" type="text" value="<?php echo esc_attr($title); ?>" style="width: 100%;" /></p>
<p><label for="<?php echo esc_attr($this->get_field_id('number')); ?>">
<?php esc_html_e('Number of posts to show:', 'disto'); ?></label>
<input id="<?php echo esc_attr($this->get_field_id('number')); ?>" name="<?php echo esc_attr($this->get_field_name('number')); ?>" type="text" value="<?php echo esc_attr($number); ?>" style="width: 100%;" /></p>
<p><label for="<?php echo esc_attr($this->get_field_id('number_offset')); ?>">
<?php esc_html_e('Offset posts:', 'disto'); ?></label>
<input id="<?php echo esc_attr($this->get_field_id('number_offset')); ?>" name="<?php echo esc_attr($this->get_field_name('number_offset')); ?>" type="text" value="<?php echo esc_attr($number_offset); ?>" style="width: 100%;" /></p>
<p>
<label for="<?php echo esc_attr($this->get_field_id('cats')); ?>">
<?php esc_html_e('Choose your category:', 'disto');?>
<?php
$categories= get_categories();
echo "<br/>";
foreach ($categories as $cat) {
$option = '<input type="checkbox" id="' . $this->get_field_id('cats') . '[]" name="' . $this->get_field_name('cats') . '[]"';
if (isset($instance['cats'])) {
foreach ($instance['cats'] as $cats) {
if ($cats == $cat->term_id) {
$option = $option . ' checked="checked"';
}
}
}
$option .= ' value="' . $cat->term_id . '" />';
$option .= ' ';
$option .= $cat->cat_name.' ('.esc_html( $cat->category_count ).')';
$option .= '<br />';
print '<span class="jl_none_space"></span>'.$option;
}
?>
</label>
</p>
<?php
}
}
?>