// Custom Widget - Display posts from a specific category // Version: 1.2 // Author: Terry Mun // Author URI: http://www.teddy-o-ted.com/ // Load Custom Theme Widgets function custom_widgets() { register_widget('posts_in_category'); } add_action('widgets_init', 'custom_widgets'); class posts_in_category extends WP_Widget { // Custom Theme Widget: Display posts from a specific category function posts_in_category() { $widget_ops = array( 'classname' => 'posts-in-category', 'description' => __('A widget that displays posts from a specific category', 'posts-in-category') ); $control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'posts-in-category-widget' ); $this->WP_Widget( 'posts-in-category-widget', __('List Posts in a Specific Category', 'posts-in-category'), $widget_ops, $control_ops ); } // Displaying widget on screen function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', $instance['title'] ); $category_id = $instance['category_id']; $post_count_limit = $instance['post_count_limit']; $post_orderby = $instance['post_orderby']; $post_offset = $instance['post_offset']; echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } $category_posts = get_posts('category=' . $category_id . '&numberposts=' . $post_count_limit . '&orderby=' . $post_orderby . '&offset= ' . $post_offset . ''); if ($category_posts) { $category_posts_result .= '