3 * Author Template functions for use in themes.
5 * These functions must be used within the WordPress Loop.
7 * @link http://codex.wordpress.org/Author_Templates
10 * @subpackage Template
14 * Retrieve the author of the current post.
17 * @uses $authordata The current author's DB object.
18 * @uses apply_filters() Calls 'the_author' hook on the author display name.
20 * @param string $deprecated Deprecated.
21 * @return string The author's display name.
23 function get_the_author($deprecated = '') {
25 return apply_filters('the_author', $authordata->display_name);
29 * Display the name of the author of the current post.
31 * The behavior of this function is based off of old functionality predating
32 * get_the_author(). This function is not deprecated, but is designed to echo
33 * the value from get_the_author() and as an result of any old theme that might
34 * still use the old behavior will also pass the value from get_the_author().
36 * The normal, expected behavior of this function is to echo the author and not
37 * return it. However, backwards compatiability has to be maintained.
40 * @see get_the_author()
41 * @link http://codex.wordpress.org/Template_Tags/the_author
43 * @param string $deprecated Deprecated.
44 * @param string $deprecated_echo Echo the string or return it.
45 * @return string The author's display name, from get_the_author().
47 function the_author($deprecated = '', $deprecated_echo = true) {
48 if ( $deprecated_echo )
49 echo get_the_author();
50 return get_the_author();
54 * Retrieve the description of the author of the current post.
57 * @uses $authordata The current author's DB object.
58 * @return string The author's description.
60 function get_the_author_description() {
62 return $authordata->description;
66 * Display the description of the author of the current post.
68 * @link http://codex.wordpress.org/Template_Tags/the_author_description
70 * @see get_the_author_description()
72 function the_author_description() {
73 echo get_the_author_description();
77 * Retrieve the login name of the author of the current post.
80 * @uses $authordata The current author's DB object.
81 * @return string The author's login name (username).
83 function get_the_author_login() {
85 return $authordata->user_login;
89 * Display the login name of the author of the current post.
91 * @link http://codex.wordpress.org/Template_Tags/the_author_login
93 * @see get_the_author_login()
95 function the_author_login() {
96 echo get_the_author_login();
100 * Retrieve the first name of the author of the current post.
103 * @uses $authordata The current author's DB object.
104 * @return string The author's first name.
106 function get_the_author_firstname() {
108 return $authordata->first_name;
112 * Display the first name of the author of the current post.
114 * @link http://codex.wordpress.org/Template_Tags/the_author_firstname
116 * @uses get_the_author_firstname()
118 function the_author_firstname() {
119 echo get_the_author_firstname();
123 * Retrieve the last name of the author of the current post.
126 * @uses $authordata The current author's DB object.
127 * @return string The author's last name.
129 function get_the_author_lastname() {
131 return $authordata->last_name;
135 * Display the last name of the author of the current post.
137 * @link http://codex.wordpress.org/Template_Tags/the_author_lastname
139 * @uses get_the_author_lastname()
141 function the_author_lastname() {
142 echo get_the_author_lastname();
146 * Retrieve the nickname of the author of the current post.
149 * @uses $authordata The current author's DB object.
150 * @return string The author's nickname.
152 function get_the_author_nickname() {
154 return $authordata->nickname;
158 * Display the nickname of the author of the current post.
160 * @link http://codex.wordpress.org/Template_Tags/the_author_nickname
162 * @uses get_the_author_nickname()
164 function the_author_nickname() {
165 echo get_the_author_nickname();
169 * Retrieve the ID of the author of the current post.
172 * @uses $authordata The current author's DB object.
173 * @return int The author's ID.
175 function get_the_author_ID() {
177 return (int) $authordata->ID;
181 * Display the ID of the author of the current post.
183 * @link http://codex.wordpress.org/Template_Tags/the_author_ID
185 * @uses get_the_author_ID()
187 function the_author_ID() {
188 echo get_the_author_id();
192 * Retrieve the email of the author of the current post.
195 * @uses $authordata The current author's DB object.
196 * @return string The author's username.
198 function get_the_author_email() {
200 return $authordata->user_email;
204 * Display the email of the author of the current post.
206 * @link http://codex.wordpress.org/Template_Tags/the_author_email
208 * @uses get_the_author_email()
210 function the_author_email() {
211 echo apply_filters('the_author_email', get_the_author_email() );
215 * Retrieve the URL to the home page of the author of the current post.
218 * @uses $authordata The current author's DB object.
219 * @return string The URL to the author's page.
221 function get_the_author_url() {
224 if ( 'http://' == $authordata->user_url )
227 return $authordata->user_url;
231 * Display the URL to the home page of the author of the current post.
233 * @link http://codex.wordpress.org/Template_Tags/the_author_url
235 * @uses get_the_author_url()
237 function the_author_url() {
238 echo get_the_author_url();
242 * Display either author's link or author's name.
244 * If the author has a home page set, echo an HTML link, otherwise just echo the
247 * @link http://codex.wordpress.org/Template_Tags/the_author_link
249 * @uses get_the_author_url()
252 function the_author_link() {
253 if (get_the_author_url()) {
254 echo '<a href="' . get_the_author_url() . '" title="' . sprintf(__("Visit %s's website"), get_the_author()) . '" rel="external">' . get_the_author() . '</a>';
261 * Retrieve the ICQ number of the author of the current post.
264 * @uses $authordata The current author's DB object.
265 * @return string The author's ICQ number.
267 function get_the_author_icq() {
269 return $authordata->icq;
273 * Display the ICQ number of the author of the current post.
275 * @link http://codex.wordpress.org/Template_Tags/the_author_icq
277 * @see get_the_author_icq()
279 function the_author_icq() {
280 echo get_the_author_icq();
284 * Retrieve the AIM name of the author of the current post.
287 * @uses $authordata The current author's DB object.
288 * @return string The author's AIM name.
290 function get_the_author_aim() {
292 return str_replace(' ', '+', $authordata->aim);
296 * Display the AIM name of the author of the current post.
298 * @link http://codex.wordpress.org/Template_Tags/the_author_aim
300 * @see get_the_author_aim()
302 function the_author_aim() {
303 echo get_the_author_aim();
307 * Retrieve the Yahoo! IM name of the author of the current post.
310 * @uses $authordata The current author's DB object.
311 * @return string The author's Yahoo! IM name.
313 function get_the_author_yim() {
315 return $authordata->yim;
319 * Display the Yahoo! IM name of the author of the current post.
321 * @link http://codex.wordpress.org/Template_Tags/the_author_yim
323 * @see get_the_author_yim()
325 function the_author_yim() {
326 echo get_the_author_yim();
330 * Retrieve the MSN address of the author of the current post.
333 * @uses $authordata The current author's DB object.
334 * @return string The author's MSN address.
336 function get_the_author_msn() {
338 return $authordata->msn;
342 * Display the MSN address of the author of the current post.
344 * @link http://codex.wordpress.org/Template_Tags/the_author_msn
346 * @see get_the_author_msn()
348 function the_author_msn() {
349 echo get_the_author_msn();
353 * Retrieve the number of posts by the author of the current post.
356 * @uses $post The current post in the Loop's DB object.
357 * @uses get_usernumposts()
358 * @return int The number of posts by the author.
360 function get_the_author_posts() {
362 return get_usernumposts($post->post_author);
366 * Display the number of posts by the author of the current post.
368 * @link http://codex.wordpress.org/Template_Tags/the_author_posts
370 * @uses get_the_author_posts() Echos returned value from function.
372 function the_author_posts() {
373 echo get_the_author_posts();
377 * Display an HTML link to the author page of the author of the current post.
379 * Does just echo get_author_posts_url() function, like the others do. The
380 * reason for this, is that another function is used to help in printing the
381 * link to the author's posts.
383 * @link http://codex.wordpress.org/Template_Tags/the_author_posts_link
385 * @uses $authordata The current author's DB object.
386 * @uses get_author_posts_url()
387 * @uses get_the_author()
388 * @param string $deprecated Deprecated.
390 function the_author_posts_link($deprecated = '') {
393 '<a href="%1$s" title="%2$s">%3$s</a>',
394 get_author_posts_url( $authordata->ID, $authordata->user_nicename ),
395 sprintf( __( 'Posts by %s' ), attribute_escape( get_the_author() ) ),
401 * Retrieve the URL to the author page of the author of the current post.
404 * @uses $wp_rewrite WP_Rewrite
405 * @return string The URL to the author's page.
407 function get_author_posts_url($author_id, $author_nicename = '') {
409 $auth_ID = (int) $author_id;
410 $link = $wp_rewrite->get_author_permastruct();
412 if ( empty($link) ) {
413 $file = get_option('home') . '/';
414 $link = $file . '?author=' . $auth_ID;
416 if ( '' == $author_nicename ) {
417 $user = get_userdata($author_id);
418 if ( !empty($user->user_nicename) )
419 $author_nicename = $user->user_nicename;
421 $link = str_replace('%author%', $author_nicename, $link);
422 $link = get_option('home') . trailingslashit($link);
425 $link = apply_filters('author_link', $link, $author_id, $author_nicename);
431 * Retrieve the specified author's preferred display name.
434 * @param int $auth_id The ID of the author.
435 * @return string The author's display name.
437 function get_author_name( $auth_id ) {
438 $authordata = get_userdata( $auth_id );
439 return $authordata->display_name;
443 * List all the authors of the blog, with several options available.
445 * optioncount (boolean) (false): Show the count in parenthesis next to the
447 * exclude_admin (boolean) (true): Exclude the 'admin' user that is installed by
449 * show_fullname (boolean) (false): Show their full names.
450 * hide_empty (boolean) (true): Don't show authors without any posts.
451 * feed (string) (''): If isn't empty, show links to author's feeds.
452 * feed_image (string) (''): If isn't empty, use this image to link to feeds.
453 * echo (boolean) (true): Set to false to return the output, instead of echoing.
455 * @link http://codex.wordpress.org/Template_Tags/wp_list_authors
457 * @param array $args The argument array.
458 * @return null|string The output, if echo is set to false.
460 function wp_list_authors($args = '') {
464 'optioncount' => false, 'exclude_admin' => true,
465 'show_fullname' => false, 'hide_empty' => true,
466 'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true
469 $r = wp_parse_args( $args, $defaults );
470 extract($r, EXTR_SKIP);
474 /** @todo Move select to get_authors(). */
475 $authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users " . ($exclude_admin ? "WHERE user_login <> 'admin' " : '') . "ORDER BY display_name");
477 $author_count = array();
478 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) {
479 $author_count[$row->post_author] = $row->count;
482 foreach ( (array) $authors as $author ) {
483 $author = get_userdata( $author->ID );
484 $posts = (isset($author_count[$author->ID])) ? $author_count[$author->ID] : 0;
485 $name = $author->display_name;
487 if ( $show_fullname && ($author->first_name != '' && $author->last_name != '') )
488 $name = "$author->first_name $author->last_name";
490 if ( !($posts == 0 && $hide_empty) )
496 $link = '<a href="' . get_author_posts_url($author->ID, $author->user_nicename) . '" title="' . sprintf(__("Posts by %s"), attribute_escape($author->display_name)) . '">' . $name . '</a>';
498 if ( (! empty($feed_image)) || (! empty($feed)) ) {
500 if (empty($feed_image))
502 $link .= '<a href="' . get_author_rss_link(0, $author->ID, $author->user_nicename) . '"';
504 if ( !empty($feed) ) {
505 $title = ' title="' . $feed . '"';
506 $alt = ' alt="' . $feed . '"';
513 if ( !empty($feed_image) )
514 $link .= "<img src=\"$feed_image\" style=\"border: none;\"$alt$title" . ' />';
520 if ( empty($feed_image) )
525 $link .= ' ('. $posts . ')';
529 if ( !($posts == 0 && $hide_empty) )
530 $return .= $link . '</li>';