'Display posts from a single category')); } /** * Displays category posts widget on blog. */ function widget($args, $instance) { global $post; $post_old = $post; // Save the post object. extract( $args ); // If not title, use the name of the category. if( !$instance["title"] ) { $category_info = get_category($instance["cat"]); $instance["title"] = $category_info->name; } $valid_sort_orders = array('date', 'title', 'comment_count', 'rand'); if ( in_array($instance['sort_by'], $valid_sort_orders) ) { $sort_by = $instance['sort_by']; $sort_order = (bool) $instance['asc_sort_order'] ? 'ASC' : 'DESC'; } else { // by default, display latest first $sort_by = 'date'; $sort_order = 'DESC'; } // Get array of post info. $cat_posts = new WP_Query( "showposts=" . $instance["num"] . "&cat=" . $instance["cat"] . "&orderby=" . $sort_by . "&order=" . $sort_order ); // Excerpt length filter $new_excerpt_length = create_function('$length', "return " . $instance["excerpt_length"] . ";"); if ( $instance["excerpt_length"] > 0 ) add_filter('excerpt_length', $new_excerpt_length); echo $before_widget; // Widget title echo $before_title; if( $instance["title_link"] ) echo '' . $instance["title"] . ''; else echo $instance["title"]; echo $after_title; // Post list echo "