Index: author-template.php
===================================================================
--- author-template.php	(revision 6360)
+++ author-template.php	(working copy)
@@ -364,7 +364,8 @@
 	global $wpdb;
 
 	$defaults = array(
-		'optioncount' => false, 'exclude_admin' => true,
+		'order' => 'ASC', 'limit' => '0', 'list' => true,
+		'link' => true, 'optioncount' => false, 'exclude_admin' => true,
 		'show_fullname' => false, 'hide_empty' => true,
 		'feed' => '', 'feed_image' => '', 'echo' => true
 	);
@@ -372,69 +373,104 @@
 	$r = wp_parse_args( $args, $defaults );
 	extract($r, EXTR_SKIP);
 
+	$exclude_admin = $exclude_admin ? "WHERE user_login <> 'admin'" : '';
+
+	$sql_limit = $limit > 0 ? "LIMIT 0,$limit" : '';
+	
 	$return = '';
 
-	// TODO:  Move select to get_authors().
-	$authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users " . ($exclude_admin ? "WHERE user_login <> 'admin' " : '') . "ORDER BY display_name");
+	$authors = (array) $wpdb->get_results("
+		SELECT $wpdb->users.ID, user_nicename, display_name, COUNT($wpdb->posts.ID) AS posts
+		FROM $wpdb->users " . (!$hide_empty ? 'LEFT' : '') . " JOIN $wpdb->posts
+			ON  $wpdb->posts.post_author = $wpdb->users.ID AND post_type = 'post' AND " . get_private_posts_cap_sql( 'post' ) . "
+		$exclude_admin
+		GROUP BY post_author
+		ORDER BY display_name $order $sql_limit");
 
-	$author_count = array();
-	foreach ((array) $wpdb->get_results("SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE post_type = 'post' AND " . get_private_posts_cap_sql( 'post' ) . " GROUP BY post_author") as $row) {
-		$author_count[$row->post_author] = $row->count;
+	if ( empty($authors) ) return false;
+
+	if ( $show_fullname ) {
+		$user_ids = $wpdb->get_col(null);
+
+		$meta = (array) $wpdb->get_results("
+			SELECT user_id, meta_key, meta_value
+			FROM $wpdb->usermeta
+			WHERE user_id IN (" . join(',', $user_ids) . ") AND (meta_key = 'first_name' OR meta_key = 'last_name')
+			ORDER BY meta_key, meta_value, user_id");
+
+		$user_meta = array();
+		foreach ($meta as $v)
+			$user_meta[$v->user_id][$v->meta_key] = $v->meta_value;
 	}
-
-	foreach ( (array) $authors as $author ) {
-		$author = get_userdata( $author->ID );
-		$posts = (isset($author_count[$author->ID])) ? $author_count[$author->ID] : 0;
+	
+	$return .= $before;
+	$i = 0;
+	if($list)
+		$return .= '<ul>';
+	foreach ($authors as $key => $author) {
 		$name = $author->display_name;
+		if ( $show_fullname && !empty($user_meta[$author->ID]['first_name']) && !empty($user_meta[$author->ID]['last_name']) )
+			$name = trim($user_meta[$author->ID]['first_name'] . ' ' . $user_meta[$author->ID]['last_name']);
 
-		if ( $show_fullname && ($author->first_name != '' && $author->last_name != '') )
-			$name = "$author->first_name $author->last_name";
-
-		if ( !($posts == 0 && $hide_empty) )
+		if ( $hide_empty && 0 == $author->posts ) {
+			if($list)
+				$return .= '<li>' . $name . '</li>';
+			else
+				$return .= $name;
+			$return .= $between;
+			continue;
+		}
+		if($list)
 			$return .= '<li>';
-		if ( $posts == 0 ) {
-			if ( !$hide_empty )
-				$link = $name;
-		} else {
-			$link = '<a href="' . get_author_posts_url($author->ID, $author->user_nicename) . '" title="' . sprintf(__("Posts by %s"), attribute_escape($author->display_name)) . '">' . $name . '</a>';
+		if($link)
+			$text = '<a href="' . get_author_posts_url($author->ID, $author->user_nicename) . '" title="' . sprintf(__("Posts by %s"), attribute_escape($author->display_name)) . '">' . $name . '</a>';
+		else
+			$text = $name;
+			
+		if ( ((! empty($feed_image)) || (! empty($feed))) && $link) {
+			$text .= ' ';
+			if (empty($feed_image))
+				$text .= '(';
+			$text .= '<a href="' . get_author_rss_link(0, $author->ID, $author->user_nicename) . '"';
 
-			if ( (! empty($feed_image)) || (! empty($feed)) ) {
-				$link .= ' ';
-				if (empty($feed_image))
-					$link .= '(';
-				$link .= '<a href="' . get_author_rss_link(0, $author->ID, $author->user_nicename) . '"';
+			if ( !empty($feed) ) {
+				$title = ' title="' . $feed . '"';
+				$alt = ' alt="' . $feed . '"';
+				$name = $feed;
+				$text .= $title;
+			}
 
-				if ( !empty($feed) ) {
-					$title = ' title="' . $feed . '"';
-					$alt = ' alt="' . $feed . '"';
-					$name = $feed;
-					$link .= $title;
-				}
+			$text .= '>';
 
-				$link .= '>';
+			if ( !empty($feed_image) )
+				$text .= "<img src=\"$feed_image\" border=\"0\"$alt$title" . ' />';
+			else
+				$text .= $name;
 
-				if ( !empty($feed_image) )
-					$link .= "<img src=\"$feed_image\" border=\"0\"$alt$title" . ' />';
-				else
-					$link .= $name;
+			$text .= '</a>';
 
-				$link .= '</a>';
+			if ( empty($feed_image) )
+				$text .= ')';
+		}
 
-				if ( empty($feed_image) )
-					$link .= ')';
-			}
+		if ( $optioncount )
+			$text .= ' ('. $author->posts . ')';
 
-			if ( $optioncount )
-				$link .= ' ('. $posts . ')';
-
-		}
-
-		if ( !($posts == 0 && $hide_empty) )
-			$return .= $link . '</li>';
+		$return .= $text;
+		if($list)
+			$return .= '</li>';
+		$i++;
+		if($i < $limit)
+			$return .= $between."\n";
+		
 	}
+	if($list)
+		$return .= '</ul>';	
+	$return .= $after;
+	
 	if ( !$echo )
 		return $return;
 	echo $return;
 }
 
-?>
\ No newline at end of file
+?>
