3 * Author Template functions for use in themes.
10 * get_the_author() - Get the author of the current post in the Loop.
13 * @uses $authordata The current author's DB object.
14 * @uses apply_filters() Calls 'the_author' hook on the author display name.
16 * @param string $deprecated Deprecated.
17 * @return string The author's display name.
19 function get_the_author($deprecated = '') {
21 return apply_filters('the_author', $authordata->display_name);
25 * the_author() - Echo the name of the author of the current post in the Loop.
27 * The behavior of this function is based off of old functionality predating get_the_author().
28 * This function is not deprecated, but is designed to echo the value from get_the_author()
29 * and as an result of any old theme that might still use the old behavior will also
30 * pass the value from get_the_author().
32 * The normal, expected behavior of this function is to echo the author and not return it.
33 * However, backwards compatiability has to be maintained.
36 * @see get_the_author()
38 * @param string $deprecated Deprecated.
39 * @param string $deprecated_echo Echo the string or return it. Deprecated, use get_the_author().
40 * @return string The author's display name, from get_the_author().
42 function the_author($deprecated = '', $deprecated_echo = true) {
43 if ( $deprecated_echo )
44 echo get_the_author();
45 return get_the_author();
49 * get_the_author_description() - Get the description of the author of the current post in the Loop.
52 * @uses $authordata The current author's DB object.
53 * @return string The author's description.
55 function get_the_author_description() {
57 return $authordata->description;
61 * the_author_description() - Echo the description of the author of the current post in the Loop.
64 * @see get_the_author_description()
66 function the_author_description() {
67 echo get_the_author_description();
71 * get_the_author_login() - Get the login name of the author of the current post in the Loop.
74 * @uses $authordata The current author's DB object.
75 * @return string The author's login name (username).
77 function get_the_author_login() {
79 return $authordata->user_login;
83 * the_author_login() - Echo the login name of the author of the current post in the Loop.
86 * @see get_the_author_login()
88 function the_author_login() {
89 echo get_the_author_login();
93 * get_the_author_firstname() - Get the first name of the author of the current post in the Loop.
96 * @uses $authordata The current author's DB object.
97 * @return string The author's first name.
99 function get_the_author_firstname() {
101 return $authordata->first_name;
105 * the_author_firstname() - Echo the first name of the author of the current post in the Loop.
108 * @uses get_the_author_firstname()
110 function the_author_firstname() {
111 echo get_the_author_firstname();
115 * get_the_author_lastname() - Get the last name of the author of the current post in the Loop.
118 * @uses $authordata The current author's DB object.
119 * @return string The author's last name.
121 function get_the_author_lastname() {
123 return $authordata->last_name;
127 * the_author_lastname() - Echo the last name of the author of the current post in the Loop.
130 * @uses get_the_author_lastname()
132 function the_author_lastname() {
133 echo get_the_author_lastname();
137 * get_the_author_nickname() - Get the nickname of the author of the current post in the Loop.
140 * @uses $authordata The current author's DB object.
141 * @return string The author's nickname.
143 function get_the_author_nickname() {
145 return $authordata->nickname;
149 * the_author_nickname() - Echo the nickname of the author of the current post in the Loop.
152 * @uses get_the_author_nickname()
154 function the_author_nickname() {
155 echo get_the_author_nickname();
159 * get_the_author_ID() - Get the ID of the author of the current post in the Loop.
162 * @uses $authordata The current author's DB object.
163 * @return int The author's ID.
165 function get_the_author_ID() {
167 return (int) $authordata->ID;
171 * the_author_ID() - Echo the ID of the author of the current post in the Loop.
174 * @uses get_the_author_ID()
176 function the_author_ID() {
177 echo get_the_author_id();
181 * get_the_author_email() - Get the email of the author of the current post in the Loop.
184 * @uses $authordata The current author's DB object.
185 * @return string The author's username.
187 function get_the_author_email() {
189 return $authordata->user_email;
193 * the_author_email() - Echo the email of the author of the current post in the Loop.
196 * @uses get_the_author_email()
198 function the_author_email() {
199 echo apply_filters('the_author_email', get_the_author_email() );
203 * get_the_author_url() - Get the URL to the home page of the author of the current post in the Loop.
206 * @uses $authordata The current author's DB object.
207 * @return string The URL to the author's page.
209 function get_the_author_url() {
212 if ( 'http://' == $authordata->user_url )
215 return $authordata->user_url;
219 * the_author_url() - Echo the URL to the home page of the author of the current post in the Loop.
222 * @uses get_the_author_url()
224 function the_author_url() {
225 echo get_the_author_url();
229 * the_author_link() - If the author has a home page set, echo an HTML link, otherwise just echo the author's name.
232 * @uses get_the_author_url()
235 function the_author_link() {
236 if (get_the_author_url()) {
237 echo '<a href="' . get_the_author_url() . '" title="' . sprintf(__("Visit %s's website"), get_the_author()) . '" rel="external">' . get_the_author() . '</a>';
244 * get_the_author_icq() - Get the ICQ number of the author of the current post in the Loop.
247 * @uses $authordata The current author's DB object.
248 * @return string The author's ICQ number.
250 function get_the_author_icq() {
252 return $authordata->icq;
256 * the_author_icq() - Echo the ICQ number of the author of the current post in the Loop.
259 * @see get_the_author_icq()
261 function the_author_icq() {
262 echo get_the_author_icq();
266 * get_the_author_aim() - Get the AIM name of the author of the current post in the Loop.
269 * @uses $authordata The current author's DB object.
270 * @return string The author's AIM name.
272 function get_the_author_aim() {
274 return str_replace(' ', '+', $authordata->aim);
278 * the_author_aim() - Echo the AIM name of the author of the current post in the Loop.
281 * @see get_the_author_aim()
283 function the_author_aim() {
284 echo get_the_author_aim();
288 * get_the_author_yim() - Get the Yahoo! IM name of the author of the current post in the Loop.
291 * @uses $authordata The current author's DB object.
292 * @return string The author's Yahoo! IM name.
294 function get_the_author_yim() {
296 return $authordata->yim;
300 * the_author_yim() - Echo the Yahoo! IM name of the author of the current post in the Loop.
303 * @see get_the_author_yim()
305 function the_author_yim() {
306 echo get_the_author_yim();
310 * get_the_author_msn() - Get the MSN address of the author of the current post in the Loop.
313 * @uses $authordata The current author's DB object.
314 * @return string The author's MSN address.
316 function get_the_author_msn() {
318 return $authordata->msn;
322 * the_author_msn() - Echo the MSN address of the author of the current post in the Loop.
325 * @see get_the_author_msn()
327 function the_author_msn() {
328 echo get_the_author_msn();
332 * get_the_author_posts() - Get the number of posts by the author of the current post in the Loop.
335 * @uses $post The current post in the Loop's DB object.
336 * @uses get_usernumposts()
337 * @return int The number of posts by the author.
339 function get_the_author_posts() {
341 return get_usernumposts($post->post_author);
345 * the_author_posts() - Echo the number of posts by the author of the current post in the Loop.
348 * @uses get_the_author_posts() Echos returned value from function.
350 function the_author_posts() {
351 echo get_the_author_posts();
355 * the_author_posts_link() - Echo an HTML link to the author page of the author of the current post in the Loop.
357 * Does just echo get_author_posts_url() function, like the others do. The reason for this,
358 * is that another function is used to help in printing the link to the author's posts.
361 * @uses $authordata The current author's DB object.
362 * @uses get_author_posts_url()
363 * @uses get_the_author()
364 * @param string $deprecated Deprecated.
366 function the_author_posts_link($deprecated = '') {
369 '<a href="%1$s" title="%2$s">%3$s</a>',
370 get_author_posts_url( $authordata->ID, $authordata->user_nicename ),
371 sprintf( __( 'Posts by %s' ), attribute_escape( get_the_author() ) ),
377 * get_author_posts_url() - Get the URL to the author page of the author of the current post in the Loop.
380 * @uses $wp_rewrite WP_Rewrite
381 * @return string The URL to the author's page.
383 function get_author_posts_url($author_id, $author_nicename = '') {
385 $auth_ID = (int) $author_id;
386 $link = $wp_rewrite->get_author_permastruct();
388 if ( empty($link) ) {
389 $file = get_option('home') . '/';
390 $link = $file . '?author=' . $auth_ID;
392 if ( '' == $author_nicename ) {
393 $user = get_userdata($author_id);
394 if ( !empty($user->user_nicename) )
395 $author_nicename = $user->user_nicename;
397 $link = str_replace('%author%', $author_nicename, $link);
398 $link = get_option('home') . trailingslashit($link);
401 $link = apply_filters('author_link', $link, $author_id, $author_nicename);
407 * get_author_name() - Get the specified author's preferred display name.
410 * @param int $auth_id The ID of the author.
411 * @return string The author's display name.
413 function get_author_name( $auth_id ) {
414 $authordata = get_userdata( $auth_id );
415 return $authordata->display_name;
419 * wp_list_authors() - List all the authors of the blog, with several options available.
421 * optioncount (boolean) (false): Show the count in parenthesis next to the author's name.
422 * exclude_admin (boolean) (true): Exclude the 'admin' user that is installed by default.
423 * show_fullname (boolean) (false): Show their full names.
424 * hide_empty (boolean) (true): Don't show authors without any posts.
425 * feed (string) (''): If isn't empty, show links to author's feeds.
426 * feed_image (string) (''): If isn't empty, use this image to link to feeds.
427 * echo (boolean) (true): Set to false to return the output, instead of echoing.
430 * @param array $args The argument array.
431 * @return null|string The output, if echo is set to false.
433 function wp_list_authors($args = '') {
437 'optioncount' => false, 'exclude_admin' => true,
438 'show_fullname' => false, 'hide_empty' => true,
439 'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true
442 $r = wp_parse_args( $args, $defaults );
443 extract($r, EXTR_SKIP);
447 /** @todo Move select to get_authors(). */
448 $authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users " . ($exclude_admin ? "WHERE user_login <> 'admin' " : '') . "ORDER BY display_name");
450 $author_count = array();
451 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) {
452 $author_count[$row->post_author] = $row->count;
455 foreach ( (array) $authors as $author ) {
456 $author = get_userdata( $author->ID );
457 $posts = (isset($author_count[$author->ID])) ? $author_count[$author->ID] : 0;
458 $name = $author->display_name;
460 if ( $show_fullname && ($author->first_name != '' && $author->last_name != '') )
461 $name = "$author->first_name $author->last_name";
463 if ( !($posts == 0 && $hide_empty) )
469 $link = '<a href="' . get_author_posts_url($author->ID, $author->user_nicename) . '" title="' . sprintf(__("Posts by %s"), attribute_escape($author->display_name)) . '">' . $name . '</a>';
471 if ( (! empty($feed_image)) || (! empty($feed)) ) {
473 if (empty($feed_image))
475 $link .= '<a href="' . get_author_rss_link(0, $author->ID, $author->user_nicename) . '"';
477 if ( !empty($feed) ) {
478 $title = ' title="' . $feed . '"';
479 $alt = ' alt="' . $feed . '"';
486 if ( !empty($feed_image) )
487 $link .= "<img src=\"$feed_image\" style=\"border: none;\"$alt$title" . ' />';
493 if ( empty($feed_image) )
498 $link .= ' ('. $posts . ')';
502 if ( !($posts == 0 && $hide_empty) )
503 $return .= $link . '</li>';