<?php
// ------------------------------------------------------
// ------ Recent Posts  ---------------------------
// ------ by Anthemes.net -------------------------------
//        http://themeforest.net/user/An-Themes/portfolio
//        http://themeforest.net/user/An-Themes/follow 
// ------------------------------------------------------

class alinan_wp_recentposts extends WP_Widget {
     function __construct() {
      $widget_ops = array('description' => esc_html__('Your site\'s most recent Posts.', 'alinan-wp'));
        parent::__construct(false, $name = ''. esc_html__('Custom: Recent Posts', 'alinan-wp') .'',$widget_ops); 
    }


    function widget($args, $instance) {   
        extract( $args );
        $number = $instance['number'];
        $title = $instance['title'];
        ?>



<?php echo wp_kses_post($before_widget); ?>
<?php if ( $title ) echo wp_kses_post($before_title) . esc_attr($title) . wp_kses_post($after_title); ?>

<ul class="article_list">
<?php $alinan_wp_latest = new WP_Query(array('post_type' => 'post', 'ignore_sticky_posts' => esc_attr(1), 'posts_per_page' => esc_attr($number) )); // number to display more / less ?>
<?php while ( $alinan_wp_latest->have_posts() ) : $alinan_wp_latest->the_post(); ?>

  <li class="img-zoom-in">
      <a href="<?php the_permalink(); ?>"> <?php echo the_post_thumbnail('alinan-wp-thumbnail-widget-small'); ?></a>
      <div class="an-widget-title" <?php if ( has_post_thumbnail()) { ?> style="margin-left:90px;" <?php } ?>>
        <a href="<?php the_permalink(); ?>"><h4 class="article-title"><?php the_title(); ?></h4></a>              
        <span class="time"><?php echo get_the_date(); ?></span>
        <?php if (get_comments_number()==0) { } else { ?><span class="comm"><i class="fas fa-comment-dots"></i> <?php comments_popup_link('0', '1', '%'); ?></span><?php } ?>
      </div>
  </li>
 
<?php endwhile; 
/* Restore original Post Data */
wp_reset_postdata(); ?>
</ul><div class="clear"></div>


<?php echo wp_kses_post($after_widget); ?> 


<?php
    }
    function update($new_instance, $old_instance) {       
    $instance = $old_instance;
    $instance['title'] = strip_tags($new_instance['title']);
    $instance['number'] = strip_tags($new_instance['number']);
    return $instance;
    }

  function form( $instance ) {
    $instance = wp_parse_args( (array) $instance );
?>


        <p>
          <label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php esc_html_e( 'Title:', 'alinan-wp' ); ?></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 if( isset($instance['title']) ) echo esc_attr($instance['title']); ?>" />
        </p>

         <p>
          <label for="<?php echo esc_attr($this->get_field_id('number')); ?>"><?php esc_html_e( 'Number of Posts:', 'alinan-wp' ); ?></label>      
          <input class="widefat" id="<?php echo esc_attr($this->get_field_id('number')); ?>" name="<?php echo esc_attr($this->get_field_name('number')); ?>" type="text" value="<?php if( isset($instance['number']) ) echo esc_attr($instance['number']); ?>" />
         </p> 
         
<?php  } }

// register widget
function alinan_wp_recentposts_init_widget () {
    return register_widget('alinan_wp_recentposts');
  }
add_action ('widgets_init', 'alinan_wp_recentposts_init_widget');
?>