<?php

Class Immigration_Consulting_My_Recent_Posts_Widget extends WP_Widget_Recent_Posts {
  function widget($immigration_consulting_args, $immigration_consulting_instance) {
      if ( ! isset( $immigration_consulting_args['widget_id'] ) ) {
      $immigration_consulting_args['widget_id'] = $this->id;
    }
    $immigration_consulting_title = ( ! empty( $immigration_consulting_instance['title'] ) ) ? $immigration_consulting_instance['title'] : __( 'Recent Posts', 'immigration-consulting' );
    /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
    $immigration_consulting_title = apply_filters( 'widget_title', $immigration_consulting_title, $immigration_consulting_instance, $this->id_base );
    $immigration_consulting_number = ( ! empty( $immigration_consulting_instance['number'] ) ) ? absint( $immigration_consulting_instance['number'] ) : 5;
    if ( ! $immigration_consulting_number )
        $immigration_consulting_number = 5;
    $immigration_consulting_show_date = isset( $immigration_consulting_instance['show_date'] ) ? $immigration_consulting_instance['show_date'] : false;
    /**
     * Filter the arguments for the Recent Posts widget.
     *
     * @since 3.4.0
     *
     * @see WP_Query::get_posts()
     *
     * @param array $immigration_consulting_args An array of arguments used to retrieve the recent posts.
     */
    $immigration_consulting_r = new WP_Query( apply_filters( 'widget_posts_args', array(
        'posts_per_page'      => $immigration_consulting_number,
        'no_found_rows'       => true,
        'post_status'         => 'publish',
        'ignore_sticky_posts' => true
    ) ) );
    if ($immigration_consulting_r->have_posts()) :
    ?>
    <?php echo $immigration_consulting_args['before_widget']; ?>
    <?php if ( $immigration_consulting_title ) {
        echo $immigration_consulting_args['before_title'] . esc_html($immigration_consulting_title) . $immigration_consulting_args['after_title'];
    } ?>
    <ul>
      <?php while ( $immigration_consulting_r->have_posts() ) : $immigration_consulting_r->the_post(); ?>
      <li>
        <div class="recent-post-box">
          <div class="media post-thumb">
            <?php if(has_post_thumbnail()) { the_post_thumbnail(); } ?>
            <div class="media-body post-content">
              <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
              <div class="d-flex date-comment">
               <?php if ( $immigration_consulting_show_date ) : ?>
                <p class="post-date"><?php the_date(); ?></p>
               <?php endif; ?>
               <div class="date-comment1"><?php comments_number( __('0 Comment', 'immigration-consulting'), __('0 Comments', 'immigration-consulting'), __('% Comments', 'immigration-consulting') ); ?></div>
              </div>
            </div>
          </div>
        </div>
      </li>
      <?php endwhile;
      wp_reset_postdata(); ?>
    </ul>

    <?php echo $immigration_consulting_args['after_widget'];

    endif;
  }
}
function immigration_consulting_my_recent_widget_registration() {
  unregister_widget('WP_Widget_Recent_Posts');
  register_widget('Immigration_Consulting_My_Recent_Posts_Widget');
}
add_action('widgets_init', 'immigration_consulting_my_recent_widget_registration');
