'mh_magazine_custom_posts_popular', 'description' => esc_html__('MH Custom Posts widget to display posts based on categories or tags.', 'mh-magazine'), 'customize_selective_refresh' => true ) ); } function widget($args, $instance) { $defaults = array('title' => '', 'link' => '', 'category' => 0, 'cats' => '', 'tags' => '', 'postcount' => 5, 'offset' => 0, 'order' => 'date', 'excerpt' => 'none', 'excerpt_length' => 35, 'thumbnails' => 'show_thumbs', 'category_label' => 0, 'sticky' => 1); $instance = wp_parse_args($instance, $defaults); $query_args = array(); if (!empty($instance['cats'])) { $category_ids = explode(',', $instance['cats']); $category_ids = array_map('trim', $category_ids); $sorted_ids = mh_magazine_sort_id_list($category_ids); } if (0 === $instance['category']) { if (!empty($sorted_ids['exclude'])) { $query_args['category__not_in'] = $sorted_ids['exclude']; } } else { $ids_to_include = array(); if (!empty($sorted_ids['include'])) { $ids_to_include = $sorted_ids['include']; } $ids_to_include[] = $instance['category']; $query_args['category__in'] = $ids_to_include; } if (!empty($instance['tags'])) { $tag_slugs = explode(',', $instance['tags']); $tag_slugs = array_map('trim', $tag_slugs); $query_args['tag_slug__in'] = $tag_slugs; } if (!empty($instance['postcount'])) { $query_args['posts_per_page'] = $instance['postcount']; } if (0 !== $instance['offset']) { $query_args['offset'] = $instance['offset']; } if ('date' !== $instance['order']) { $query_args['orderby'] = $instance['order']; } if (1 === $instance['sticky']) { $query_args['ignore_sticky_posts'] = true; } $counter = 1; $widget_loop = new WP_Query($query_args); echo $args['before_widget']; if (!empty($instance['title'])) { echo $args['before_title']; if (!empty($instance['link'])) { echo ''; } elseif ($instance['category'] != 0) { echo ''; } echo esc_html(apply_filters('widget_title', $instance['title'])); if (!empty($instance['link']) || $instance['category'] != 0) { echo ''; } echo $args['after_title']; } $instance['thumbnails'] == 'show_thumbs' || $instance['thumbnails'] == 'hide_large' ? $cp_no_image = '' : $cp_no_image = ' mh-custom-posts-no-image'; ?> 50) { $instance['postcount'] = 50; } else { $instance['postcount'] = absint($new_instance['postcount']); } } if (0 !== absint($new_instance['offset'])) { if (absint($new_instance['offset']) > 50) { $instance['offset'] = 50; } else { $instance['offset'] = absint($new_instance['offset']); } } if ('date' !== $new_instance['order']) { if (in_array($new_instance['order'], array('rand', 'comment_count'))) { $instance['order'] = $new_instance['order']; } } if ('none' !== $new_instance['excerpt']) { if (in_array($new_instance['excerpt'], array('first', 'all'))) { $instance['excerpt'] = $new_instance['excerpt']; } } if (0 !== absint($new_instance['excerpt_length'])) { $instance['excerpt_length'] = absint($new_instance['excerpt_length']); } if ('show_thumbs' !== $new_instance['thumbnails']) { if (in_array($new_instance['thumbnails'], array('hide_thumbs', 'hide_large', 'hide_small'))) { $instance['thumbnails'] = $new_instance['thumbnails']; } } $instance['category_label'] = (!empty($new_instance['category_label'])) ? 1 : 0; $instance['sticky'] = (!empty($new_instance['sticky'])) ? 1 : 0; return $instance; } function form($instance) { $defaults = array('title' => '', 'link' => '', 'category' => 0, 'cats' => '', 'tags' => '', 'postcount' => 5, 'offset' => 0, 'order' => 'date', 'excerpt' => 'none', 'excerpt_length' => 35, 'thumbnails' => 'show_thumbs', 'category_label' => 0, 'sticky' => 1); $instance = wp_parse_args($instance, $defaults); ?>

/>

/>