'header_post_grid', 'description' => __('Header Grid Widget to display posts in grid format based on categories or tags. Please use it in Homepage Header', 'bloom-feminine')); parent::__construct('homepage-header', __('Header Post Grid', 'bloom-feminine'), $widget_ops); } function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base); $category = isset($instance['category']) ? $instance['category'] : ''; $tags = empty($instance['tags']) ? '' : $instance['tags']; $postcount = empty($instance['postcount']) ? '6' : $instance['postcount']; $offset = empty($instance['offset']) ? '' : $instance['offset']; $sticky = isset($instance['sticky']) ? $instance['sticky'] : 0; echo $before_widget; if (!empty( $title)) { echo $before_title .'

' . esc_html($title) .'

' . $after_title; } $args = array('posts_per_page' => $postcount, 'offset' => $offset, 'cat' => $category, 'tag' => $tags, 'ignore_sticky_posts' => $sticky); $counter = 1; $the_query = new WP_Query($args); if($the_query->have_posts()): $count = 0; $remaining_posts = ''; $first_grid_post = ''; $image_size=''; while ( $the_query->have_posts() ) : $the_query->the_post(); $post_id = get_the_ID(); $img_src= ''; if($count < 2){$image_size="gum_bloom_600X360";} else{$image_size="gum_bloom_300X180";} if ( has_post_thumbnail($post_id ) ) { $post_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), $image_size ); $img_src = $post_image[0]; } $post_permalink = get_the_permalink(); $post_title = get_the_title(); $post_date = get_the_date('M d, Y'); $author1=get_the_author(); $post_categories = wp_get_post_categories( $post_id ); $excerpt = wp_trim_words(get_the_excerpt(), 20, '...'); $cat_html = ''; if(!empty($post_categories)){ foreach($post_categories as $post_category){ $cat = get_category( $post_category ); $cat_html .= '
  • '.esc_html($cat->name).'
  • '; } } if($count < 2){ $first_grid_post .='
      '.$cat_html.'
    '.esc_html($post_title).'

    '.esc_html($post_title).'

    '.esc_html($excerpt).'

    '; } // count==0 else{ $remaining_posts .= '
      '.$cat_html.'
    '.esc_html($post_title).'

    '.esc_html($post_title).'

    '; } $count++; endwhile; wp_reset_postdata(); ?>
    '', 'category' => '', 'tags' => '','sticky' => 0, 'offset' => 0); $instance = wp_parse_args((array) $instance, $defaults); ?>

    />