'business_x_category_widget_recent_posts_template2', 'description' => esc_html__( "The most recent posts on your site", 'business-x') ); parent::__construct('category-posts-template1', esc_html__('BX : Recent Category Post(Style 2)', 'business-x'), $widget_ops); $this->alt_option_name = 'widget_recent_post_template1'; add_action( 'save_post', array($this, 'business_x_category_flush_widget_cache_temlate3') ); add_action( 'deleted_post', array($this, 'business_x_category_flush_widget_cache_temlate3') ); add_action( 'switch_theme', array($this, 'business_x_category_flush_widget_cache_temlate3') ); } function widget($args, $instance) { wp_enqueue_style( 'business-x-template2', get_template_directory_uri().'/inc/widgets/business-x-category-widgets-style2/style2.css',array(),null, false); $business_x_category_cache = wp_cache_get('business_x_category_widget_recent_posts_template2', 'widget'); if ( !is_array($business_x_category_cache) ) $business_x_category_cache = array(); if ( ! isset( $args['widget_id'] ) ) $args['widget_id'] = $this->id; if ( isset( $business_x_category_cache[ $args['widget_id'] ] ) ) { echo esc_attr($business_x_category_cache[ $args['widget_id'] ]); return; } ob_start(); extract($args); $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : esc_html__( 'Recent Posts', 'business-x' ); $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); $number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 3; $category_list = isset($instance['category']) ? $instance['category'] : ''; if ( ! $number ) $number = 3; ?> $number,'category__in' => $category_list, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true ) ) ); if ($business_x_category_r->have_posts()) : echo $args['before_widget']; if ( $title ) echo $args['before_title'] . esc_html($title) . $args['after_title']; ?>
have_posts() ) : $business_x_category_r->the_post(); $post_id = get_the_ID(); $category = get_the_category($post_id); if (has_post_thumbnail()){ $image_array = wp_get_attachment_image_src(get_post_thumbnail_id($post_id), 'large'); $image = $image_array[0]; }else{ $image = get_template_directory_uri() .'/assets/images/no-image.png'; } if($count < $number ): ?>
$cat){$class = ($key % 2 == 0)?"gaming":"business"; ?> name); ?>
business_x_category_flush_widget_cache_temlate3(); $alloptions = wp_cache_get( 'alloptions', 'options' ); if ( isset($alloptions['business_x_category_widget_recent_posts_template2']) ) delete_option('business_x_category_widget_recent_posts_template2'); return $instance; } function business_x_category_flush_widget_cache_temlate3() { wp_cache_delete('business_x_category_widget_recent_posts_template2', 'widget'); } function form( $instance ) { $category_list = isset($instance['category']) ? esc_attr($instance['category']) : ''; $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; $number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 3; ?>

' Select', 'name'=> $this->get_field_name('category'),'selected'=> $category_list)); ?>