<?php

Class Repair_Shop_My_Recent_Posts_Widget extends WP_Widget_Recent_Posts {
  function widget($repair_shop_args, $repair_shop_instance) {
      if ( ! isset( $repair_shop_args['widget_id'] ) ) {
      $repair_shop_args['widget_id'] = $this->id;
    }
    $repair_shop_title = ( ! empty( $repair_shop_instance['title'] ) ) ? $repair_shop_instance['title'] : __( 'Recent Posts', 'repair-shop' );
    /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
    $repair_shop_title = apply_filters( 'widget_title', $repair_shop_title, $repair_shop_instance, $this->id_base );
    $repair_shop_number = ( ! empty( $repair_shop_instance['number'] ) ) ? absint( $repair_shop_instance['number'] ) : 5;
    if ( ! $repair_shop_number )
        $repair_shop_number = 5;
    $repair_shop_show_date = isset( $repair_shop_instance['show_date'] ) ? $repair_shop_instance['show_date'] : false;
    /**
     * Filter the arguments for the Recent Posts widget.
     *
     * @since 3.4.0
     *
     * @see WP_Query::get_posts()
     *
     * @param array $repair_shop_args An array of arguments used to retrieve the recent posts.
     */
    $repair_shop_r = new WP_Query( apply_filters( 'widget_posts_args', array(
        'posts_per_page'      => $repair_shop_number,
        'no_found_rows'       => true,
        'post_status'         => 'publish',
        'ignore_sticky_posts' => true
    ) ) );
    if ($repair_shop_r->have_posts()) :
    ?>
    <?php echo $repair_shop_args['before_widget']; ?>
    <?php if ( $repair_shop_title ) {
        echo $repair_shop_args['before_title'] . esc_html($repair_shop_title) . $repair_shop_args['after_title'];
    } ?>
    <ul>
      <?php while ( $repair_shop_r->have_posts() ) : $repair_shop_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 ( $repair_shop_show_date ) : ?>
                <p class="post-date"><?php the_date(); ?></p>
               <?php endif; ?>
               <div class="date-comment1"><?php comments_number( __('0 Comment', 'repair-shop'), __('0 Comments', 'repair-shop'), __('% Comments', 'repair-shop') ); ?></div>
              </div>
            </div>
          </div>
        </div>
      </li>
      <?php endwhile;
      wp_reset_postdata(); ?>
    </ul>

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

    endif;
  }
}
function repair_shop_my_recent_widget_registration() {
  unregister_widget('WP_Widget_Recent_Posts');
  register_widget('Repair_Shop_My_Recent_Posts_Widget');
}
add_action('widgets_init', 'repair_shop_my_recent_widget_registration');
