<?php

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

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

    endif;
  }
}
function manufacturing_plant_my_recent_widget_registration() {
  unregister_widget('WP_Widget_Recent_Posts');
  register_widget('Manufacturing_Plant_My_Recent_Posts_Widget');
}
add_action('widgets_init', 'manufacturing_plant_my_recent_widget_registration');
