Support » Plugins » get authors

  • This hack shows the authors of your weblog

    function get_authors($postCount = true, $excludeAdmin = true) {
    global $tableusers, $tableposts, $wpdb, $author;
    echo "<div id='authors'>";
    echo "

      ";
      $query = "SELECT ID, user_nickname from $tableusers " . ($excludeAdmin ? "WHERE user_nickname <> 'admin' " : '') . "ORDER BY user_nickname";
      $res = $wpdb->get_results($query);
      foreach($res as $data) {
      $posts = ($postCount ? $wpdb->get_var("SELECT count(*) FROM $tableposts WHERE post_author=$data->ID") : 0);
      echo "

    • " . (@($data->ID == $author) ? $data->user_nickname : "ID\">$data->user_nickname".($posts ? " ($posts)" : '')."") . '
    • ' ;
      }
      echo "

    ";
    echo "</div>";
    }

    The function call could look like this: <?php get_authors(false, true); ?>
    It works with Soarian 1.0.1
    For a demo take a look at blog.lennartgroetzbach.de

Viewing 15 replies - 1 through 15 (of 17 total)
  • doesn’t
    [code]<?php get_authors(‘ ‘); ?>[/code]
    not still work?
    I thought it did

    Oops. Then its implemented in 1.0. Maybe I should have posted my code earlier…
    Thanks stew!

    Ryan Boren

    (@ryan)

    WordPress Dev

    Unless I’ve forgotten how to use grep, there is no get_authors that ships with WordPress.
    lennart, I changed your get_authors slightly. It now uses $siteurl/$blogfilename and get_usernumposts(). You can see the changes here.
    I added this to an authors.php file and added a rewrite rule to make it available via a cruft-free URL: /authors/.
    Something I would like to do is provide a search by author nickname rather than ID so that we could do something like /authors/ryan/. We would probably need to add an author_nicename field like we do with category_nicename. Hmm, I might implement this today, assuming I can finish some other coding chores for the wage-paying day job.
    Ryan

    *cough* post to wiki.

    *cough* allusion *cough* work on code.
    *cough* Craig *cough* Cena * nag people about adding code to Wiki! 🙂
    Craig.

    *cough* *COUGH COUGH COUGH*
    <–has the flu and therefore has been much less active of late.

    Awww feel better!

    Allusion: *cough* will do. As well as my other post…
    rboren: thx and nice idea, I will try it out after I get home from work

    I updated your version a bit, rboren.
    It now does not show links for users who did not post anything yet. The source code is here.

    Ryan Boren

    (@ryan)

    WordPress Dev

    Good stuff. Perhaps we can get this and clean author URLs in 1.1, assuming Matt doesn’t have a coughing fit in response to the suggestion. 🙂

    This hack is very neat 😀
    It’d rock if it’d show their profile instead of their posts. ..or maybe both?

    There are 3 people on my blog, and they each have their own little info box. I was wondering if I could work this hack so I could turn their names into links so if you clicked on the name it would show all their posts. It seems like it would be easy…I’ll play around with it.

    Cool hack.
    How would you change the code so that it would show the first and last name instead of the nickname? My blog has alot of authors.
    Thanks.

    Bring on the profile-showing version!
    Is the profile accessible anywhere in WP at all at the moment (apart from where you fill it in)?

    mhjb, take a look at this thread:
    http://wordpress.org/support/10/1793

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘get authors’ is closed to new replies.