Advertisements

wp_list_authors

Definition:
function wp_list_authors($args = '') {}

List all the authors of the blog, with several options available.

Parameters

  • array $args: The argument array.

Return values

returns:The output, if echo is set to false.

Source code

function wp_list_authors($args = '') {

	global $wpdb;



	$defaults = array(

		'orderby' => 'name', 'order' => 'ASC', 'number' => '',

		'optioncount' => false, 'exclude_admin' => true,

		'show_fullname' => false, 'hide_empty' => true,

		'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true,

		'style' => 'list', 'html' => true

	);



	$args = wp_parse_args( $args, $defaults );

	extract( $args, EXTR_SKIP );



	$return = '';



	$query_args = wp_array_slice_assoc( $args, array( 'orderby', 'order', 'number' ) );

	$query_args['fields'] = 'ids';

	$authors = get_users( $query_args );



	$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;



	foreach ( $authors as $author_id ) {

		$author = get_userdata( $author_id );



		if ( $exclude_admin && 'admin' == $author->display_name )

			continue;



		$posts = isset( $author_count[$author->ID] ) ? $author_count[$author->ID] : 0;



		if ( !$posts && $hide_empty )

			continue;



		$link = '';



		if ( $show_fullname && $author->first_name && $author->last_name )

			$name = "$author->first_name $author->last_name";

		else

			$name = $author->display_name;



		if ( !$html ) {

			$return .= $name . ', ';



			continue; // No need to go further to process HTML.

		}



		if ( 'list' == $style ) {

			$return .= '<li>';

		}



		$link = '<a href="' . get_author_posts_url( $author->ID, $author->user_nicename ) . '" title="' . esc_attr( sprintf(__("Posts by %s"), $author->display_name) ) . '">' . $name . '</a>';



		if ( !empty( $feed_image ) || !empty( $feed ) ) {

			$link .= ' ';

			if ( empty( $feed_image ) ) {

				$link .= '(';

			}



			$link .= '<a href="' . get_author_feed_link( $author->ID ) . '"';



			$alt = $title = '';

			if ( !empty( $feed ) ) {

				$title = ' title="' . esc_attr( $feed ) . '"';

				$alt = ' alt="' . esc_attr( $feed ) . '"';

				$name = $feed;

				$link .= $title;

			}



			$link .= '>';



			if ( !empty( $feed_image ) )

				$link .= '<img src="' . esc_url( $feed_image ) . '" style="border: none;"' . $alt . $title . ' />';

			else

				$link .= $name;



			$link .= '</a>';



			if ( empty( $feed_image ) )

				$link .= ')';

		}



		if ( $optioncount )

			$link .= ' ('. $posts . ')';



		$return .= $link;

		$return .= ( 'list' == $style ) ? '</li>' : ', ';

	}



	$return = rtrim($return, ', ');



	if ( !$echo )

		return $return;



	echo $return;

}

3851

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: