Current File : /home/bravrvjk/cepurhuye.rw/wp-content/plugins/bopea-function/widget//recent-small.php
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
add_action( 'widgets_init', 'bopea_recent_text_widgets' );
function bopea_recent_text_widgets() {
register_widget( 'bopea_recent_post_text_widget' );
}
class bopea_recent_post_text_widget extends WP_Widget {
/*-----------------------------------------------------------------------------------*/
/* Widget Setup
/*-----------------------------------------------------------------------------------*/
public function __construct() {
$widget_ops = array(
'classname' => 'post_list_widget',
'description' => esc_html__('Display a list of recent post.', 'bopea-function')
);
parent::__construct('bopea_recent_post_text_widget', esc_html__(' Recently Posts', 'bopea-function'), $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;
if (isset($instance['en_number_over'])==''){$en_number_over = '';}else{$en_number_over = absint($instance['en_number_over']);}
$post_cat_args = array(
'showposts' => $number,
'category__in' => $cats,
'ignore_sticky_posts' => 1,
'post__not_in' => array( get_the_ID() ),
'offset' => $number_offset
);
$post_cat_widget = null;
$post_cat_widget = new WP_Query($post_cat_args);
print $before_widget;
print '<div class="widget_jl_wrapper">';
if ( $title ){
print $before_title . esc_attr($title) . $after_title;
}
// Post list in widget
print '<div class="bt_post_widget">';
$i=0;
while ($post_cat_widget->have_posts()) {
$i++;
$post_cat_widget->the_post();
$post_id = get_the_ID();
?>
<div class="jl_mmlist_layout jl_li_num">
<div class="jl_li_in">
<?php if ( has_post_thumbnail()) {?>
<div class="jl_img_holder">
<div class="jl_imgw jl_radus_e">
<div class="jl_imgin">
<?php
$sm_list_auto_height = get_theme_mod('sm_list_auto_height');
if(!empty($sm_list_auto_height)){
the_post_thumbnail('medium');
}else{
the_post_thumbnail('bopea_small');
}
?>
</div>
<span class="jl_li_lbl"></span>
<a class="jl_imgl" href="<?php the_permalink();?>"></a>
</div>
</div>
<?php }?>
<div class="jl_fe_text">
<?php bopea_post_cat(get_the_ID());?>
<h3 class="jl_fe_title jl_txt_2row"><a href="<?php the_permalink(); ?>"><?php the_title()?></a></h3>
<?php bopea_post_meta_date(get_the_ID());?>
</div>
</div>
</div>
<?php }
wp_reset_postdata();
print "</div>";
print $after_widget;
print "</div>";
}
/*-----------------------------------------------------------------------------------*/
/* Update Widget
/*-----------------------------------------------------------------------------------*/
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['cats'] = isset($new_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><span class="widefat">
<?php esc_html_e('Title:', 'bopea-function'); ?></span>
<input class="widefat" name="<?php echo esc_attr($this->get_field_name('title')); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
<p><span class="widefat">
<?php esc_html_e('Number of posts to show:', 'bopea-function'); ?></span>
<input name="<?php echo esc_attr($this->get_field_name('number')); ?>" type="text" value="<?php echo esc_attr($number); ?>" style="width: 100%;" /></p>
<p><span class="widefat">
<?php esc_html_e('Offset posts:', 'bopea-function'); ?></span>
<input 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>
<span class="widefat">
<?php esc_html_e('Choose your category:', 'bopea-function');?>
<?php
$categories= get_categories();
print "<br/>";
foreach ($categories as $cat) {
$option = '<input type="checkbox" name="' . $this->get_field_name('cats') . '[]"';
if (!empty($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 $option;
}
?>
</span>
</p>
<?php
}
}
?>