'mh_magazine_lite_posts_stacked', 'description' => esc_html__('MH Posts Stacked widget to display 5 stacked posts nicely including thumbnail, title and meta data.', 'mh-magazine-lite'), 'customize_selective_refresh' => true ) ); } function widget($args, $instance) { $defaults = array('title' => '', 'category' => 0, 'tags' => '', 'postcount' => 5, 'offset' => 0, 'sticky' => 1); $instance = wp_parse_args($instance, $defaults); $query_args = array(); $query_args['posts_per_page'] = $instance['postcount']; $query_args['ignore_sticky_posts'] = $instance['sticky']; if (0 !== $instance['category']) { $query_args['cat'] = $instance['category']; } if (!empty($instance['tags'])) { $tag_slugs = explode(',', $instance['tags']); $tag_slugs = array_map('trim', $tag_slugs); $query_args['tag_slug__in'] = $tag_slugs; } if (0 !== $instance['offset']) { $query_args['offset'] = $instance['offset']; } $widget_posts = new WP_Query($query_args); $max_posts = $widget_posts->post_count; echo $args['before_widget']; if ($widget_posts->have_posts()) : $counter = 1; $stacked_border = ''; if (!empty($instance['title'])) { echo $args['before_title']; if ($instance['category'] != 0) { echo ''; } echo esc_html(apply_filters('widget_title', $instance['title'])); if ($instance['category'] != 0) { echo ''; } echo $args['after_title']; } echo '
' . "\n"; while ($widget_posts->have_posts()) : $widget_posts->the_post(); if ($counter === 1) { ?>
'; } ?>
' . "\n"; } if ($counter === 4 || $counter === 5) { $stacked_border = ' mh-posts-stacked-overlay-last'; } if ($counter >= 2) { ?>
'; } ?>
1 && $counter === $max_posts) { echo '
' . "\n"; } $counter++; endwhile; wp_reset_postdata(); echo '' . "\n"; endif; echo $args['after_widget']; } function update($new_instance, $old_instance) { $instance = array(); if (!empty($new_instance['title'])) { $instance['title'] = sanitize_text_field($new_instance['title']); } if (0 !== absint($new_instance['category'])) { $instance['category'] = absint($new_instance['category']); } if (!empty($new_instance['tags'])) { $tag_slugs = explode(',', $new_instance['tags']); $tag_slugs = array_map('sanitize_title', $tag_slugs); $instance['tags'] = implode(', ', $tag_slugs); } if (0 !== absint($new_instance['offset'])) { if (absint($new_instance['offset']) > 50) { $instance['offset'] = 50; } else { $instance['offset'] = absint($new_instance['offset']); } } return $instance; } function form($instance) { $defaults = array('title' => '', 'category' => 0, 'tags' => '', 'offset' => 0, 'sticky' => 1); $instance = wp_parse_args($instance, $defaults); ?>