__('Recent Posts Extended Widget', 'beautymatters'),) // Args ); } /** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget($args, $instance) { echo '
'; if (!empty($instance['title'])) { echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title']; } $show_current_category = (isset($instance['show_current_category']) && $instance['show_current_category'] == 'on') ? 'true' : 'false'; $number_of_posts = isset($instance['number_of_posts']) ? $instance['number_of_posts'] : '10'; $category_id = ''; if ($show_current_category == 'true') { $categories = get_the_category(); $category_id = $categories[0]->cat_ID; } $args = array( 'posts_per_page' => $number_of_posts, 'offset' => 0, 'category' => $category_id, 'category_name' => '', 'orderby' => 'date', 'order' => 'DESC', 'include' => '', 'exclude' => '', 'meta_key' => '', 'meta_value' => '', 'post_type' => 'post', 'post_mime_type' => '', 'post_parent' => '', 'author' => '', 'post_status' => 'publish', 'suppress_filters' => true ); $posts_array = get_posts($args); echo ''; echo '
'; } /** * Back-end widget form. * * @see WP_Widget::form() * * @param array $instance Previously saved values from database. */ public function form($instance) { $title = (isset($instance['title'])) ? $instance['title'] : __('Last Posts', 'beautymatters'); $number_of_posts = (isset($instance['number_of_posts'])) ? $instance['number_of_posts'] : "10"; ?>

id="get_field_id('show_current_category'); ?>" name="get_field_name('show_current_category'); ?>" />