Make WordPress Core


Ignore:
Timestamp:
03/19/2004 04:20:49 PM (20 years ago)
Author:
rboren
Message:

Introducing wp_list_authors() and friends.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/template-functions-author.php

    r801 r979  
    6464}
    6565
     66function get_author_link($echo = false, $author_id, $author_nicename) {
     67    global $wpdb, $tableusers, $post, $querystring_start, $querystring_equal, $cache_authors;
     68    $auth_ID = $author_id;
     69    $permalink_structure = get_settings('permalink_structure');
     70   
     71    if ('' == $permalink_structure) {
     72        $file = get_settings('siteurl') . '/' . get_settings('blogfilename');
     73        $link = $file.$querystring_start.'author'.$querystring_equal.$auth_ID;
     74    } else {
     75        if ('' == $author_nicename) $author_nicename = $cache_authors[$author_id]->author_nicename;
     76        // Get any static stuff from the front
     77        $front = substr($permalink_structure, 0, strpos($permalink_structure, '%'));
     78        $link = get_settings('siteurl') . $front . 'author/';
     79        $link .= $author_nicename . '/';
     80    }
     81
     82    if ($echo) echo $link;
     83    return $link;
     84}
     85
     86function get_author_rss_link($echo = false, $author_id, $author_nicename) {
     87       global $querystring_start, $querystring_equal;
     88       $auth_ID = $author_id;
     89       $permalink_structure = get_settings('permalink_structure');
     90
     91       if ('' == $permalink_structure) {
     92           $file = get_settings('siteurl') . '/wp-rss2.php';
     93           $link = $file . $querystring_start . 'author' . $querystring_equal . $author_id;
     94       } else {
     95           $link = get_author_link(0, $author_id, $author_nicename);
     96           $link = $link . "feed/";
     97       }
     98
     99       if ($echo) echo $link;
     100       return $link;
     101}
     102
     103function wp_list_authors($args = '') {
     104    parse_str($args, $r);
     105    if (!isset($r['optioncount'])) $r['optioncount'] = false;
     106    if (!isset($r['exclude_admin'])) $r['exclude_admin'] = true;
     107    if (!isset($r['show_fullname'])) $r['show_fullname'] = false;
     108    if (!isset($r['hide_empty'])) $r['hide_empty'] = true;
     109
     110    list_authors($r['optioncount'], $r['exclude_admin'], $r['show_fullname'], $r[hide_empty]);
     111}
     112
     113function list_authors($optioncount = false, $exclude_admin = true, $show_fullname = false, $hide_empty = true) {
     114    global $tableusers, $wpdb, $blogfilename;
     115
     116    $query = "SELECT ID, user_nickname, user_firstname, user_lastname, user_nicename from $tableusers " . ($exclude_admin ? "WHERE user_nickname <> 'admin' " : '') . "ORDER BY user_nickname";
     117    $authors = $wpdb->get_results($query);
     118
     119    foreach($authors as $author) {
     120        $posts = get_usernumposts($author->ID);
     121        $name = $author->user_nickname;
     122
     123        if ($show_fullname && ($author->user_firstname != '' && $author->user_lastname != '')) {
     124            $name = "$author->user_firstname $author->user_lastname";
     125        }
     126       
     127        if (! ($posts == 0 && $hide_empty)) echo "<li>";
     128        if ($posts == 0) {
     129            if (! $hide_empty) echo $name;
     130        } else {
     131            echo '<a href="' . get_author_link(0, $author->ID, $author->user_nicename) . '" title="Posts by ' . $author->user_nickname . '">' . $name . ($optioncount ? " ($posts)" : '')."</a>";
     132        }
     133        if (! ($posts == 0 && $hide_empty)) echo "</li>";
     134    }
     135}
     136
    66137?>
Note: See TracChangeset for help on using the changeset viewer.