From 8974c946a7a754b4dbf49857d961d7c7a18aca05 Mon Sep 17 00:00:00 2001 From: rboren Date: Fri, 19 Mar 2004 16:20:49 +0000 Subject: [PATCH] Introducing wp_list_authors() and friends. git-svn-id: http://svn.automattic.com/wordpress/trunk@979 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-blog-header.php | 5 ++ wp-includes/template-functions-author.php | 71 +++++++++++++++++++++ wp-includes/template-functions-category.php | 2 +- 3 files changed, 77 insertions(+), 1 deletion(-) diff --git a/wp-blog-header.php b/wp-blog-header.php index a0da6fe9f4..e4f1f760c8 100644 --- a/wp-blog-header.php +++ b/wp-blog-header.php @@ -257,6 +257,11 @@ if ('' != $category_name) { } // author stuff +$auteurs = $wpdb->get_results("SELECT * FROM $tableusers WHERE 1=1"); +foreach ($auteurs as $auteur) { + $cache_authors[$auteur->ID] = $auteur; +} + if ((empty($author)) || ($author == 'all') || ($author == '0')) { $whichauthor=''; } else { diff --git a/wp-includes/template-functions-author.php b/wp-includes/template-functions-author.php index 955b657fb3..fad647bddf 100644 --- a/wp-includes/template-functions-author.php +++ b/wp-includes/template-functions-author.php @@ -63,4 +63,75 @@ function the_author_posts() { global $id,$postdata; $posts=get_usernumposts($post->post_author); echo $posts; } +function get_author_link($echo = false, $author_id, $author_nicename) { + global $wpdb, $tableusers, $post, $querystring_start, $querystring_equal, $cache_authors; + $auth_ID = $author_id; + $permalink_structure = get_settings('permalink_structure'); + + if ('' == $permalink_structure) { + $file = get_settings('siteurl') . '/' . get_settings('blogfilename'); + $link = $file.$querystring_start.'author'.$querystring_equal.$auth_ID; + } else { + if ('' == $author_nicename) $author_nicename = $cache_authors[$author_id]->author_nicename; + // Get any static stuff from the front + $front = substr($permalink_structure, 0, strpos($permalink_structure, '%')); + $link = get_settings('siteurl') . $front . 'author/'; + $link .= $author_nicename . '/'; + } + + if ($echo) echo $link; + return $link; +} + +function get_author_rss_link($echo = false, $author_id, $author_nicename) { + global $querystring_start, $querystring_equal; + $auth_ID = $author_id; + $permalink_structure = get_settings('permalink_structure'); + + if ('' == $permalink_structure) { + $file = get_settings('siteurl') . '/wp-rss2.php'; + $link = $file . $querystring_start . 'author' . $querystring_equal . $author_id; + } else { + $link = get_author_link(0, $author_id, $author_nicename); + $link = $link . "feed/"; + } + + if ($echo) echo $link; + return $link; +} + +function wp_list_authors($args = '') { + parse_str($args, $r); + if (!isset($r['optioncount'])) $r['optioncount'] = false; + if (!isset($r['exclude_admin'])) $r['exclude_admin'] = true; + if (!isset($r['show_fullname'])) $r['show_fullname'] = false; + if (!isset($r['hide_empty'])) $r['hide_empty'] = true; + + list_authors($r['optioncount'], $r['exclude_admin'], $r['show_fullname'], $r[hide_empty]); +} + +function list_authors($optioncount = false, $exclude_admin = true, $show_fullname = false, $hide_empty = true) { + global $tableusers, $wpdb, $blogfilename; + + $query = "SELECT ID, user_nickname, user_firstname, user_lastname, user_nicename from $tableusers " . ($exclude_admin ? "WHERE user_nickname <> 'admin' " : '') . "ORDER BY user_nickname"; + $authors = $wpdb->get_results($query); + + foreach($authors as $author) { + $posts = get_usernumposts($author->ID); + $name = $author->user_nickname; + + if ($show_fullname && ($author->user_firstname != '' && $author->user_lastname != '')) { + $name = "$author->user_firstname $author->user_lastname"; + } + + if (! ($posts == 0 && $hide_empty)) echo "
  • "; + if ($posts == 0) { + if (! $hide_empty) echo $name; + } else { + echo '' . $name . ($optioncount ? " ($posts)" : '').""; + } + if (! ($posts == 0 && $hide_empty)) echo "
  • "; + } +} + ?> \ No newline at end of file diff --git a/wp-includes/template-functions-category.php b/wp-includes/template-functions-category.php index c79dd10407..e058516f39 100644 --- a/wp-includes/template-functions-category.php +++ b/wp-includes/template-functions-category.php @@ -46,7 +46,7 @@ function get_category_rss_link($echo = false, $category_id, $category_nicename) $link = $file . $querystring_start . 'cat' . $querystring_equal . $category_id; } else { $link = get_category_link(0, $category_id, $category_nicename); - $link = $link . "/feed/"; + $link = $link . "feed/"; } if ($echo) echo $link;