<?php

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

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

    endif;
  }
}
function commercial_automation_services_my_recent_widget_registration() {
  unregister_widget('WP_Widget_Recent_Posts');
  register_widget('Commercial_Automation_Services_My_Recent_Posts_Widget');
}
add_action('widgets_init', 'commercial_automation_services_my_recent_widget_registration');
