PHP Loop for Wordpress authors

Discussion in 'WordPress' started by JakeThePeg, Dec 10, 2008.

  1. #1
    I would like to create a piece of code that loops through each Author in my Wordpress blog.

    I'm a complete novice with PHP, but basically I want to list all of the Authors in an unordered list, with their Photograph, and then their name. Both the photograph and the name need to be a hyperlink that points to the Author page.

    I've worked out how to display a single Author's photo. It is as follows (the $user variable is the Author ID)
    `<?php userphoto_thumbnail($user, ' ', ' ', array(style => 'border:0')) ?>`
    
    PHP:
    From previous research, it seems that this is how you list all Author usernames as a list of hyperlinks to their respective pages, though I don't think it's going to help me in this instance
    `<?php wp_list_authors('exclude_admin=0'); ?>
    `
    PHP:
    Could anyone help me write the loop code, pretty please?
     
    JakeThePeg, Dec 10, 2008 IP
  2. Ikki

    Ikki Peon

    Messages:
    474
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi there,

    I did not test this but it should work:
    
    <?php
    $results = $wpdb->get_results("SELECT ID, display_name FROM $wpdb->wp_users");
    	
    	echo "<ul>";
    	foreach ($results as $user) {
    		echo "<li>" . userphoto_thumbnail($user->ID, ' ', ' ', array(style => 'border:0')) . " " . $user->display_name . "</li>";
    	}
    	echo "</ul>";
    ?>
    
    PHP:
    You still need to tweak it a bit using CSS, though.

    Good luck!
     
    Ikki, Dec 10, 2008 IP
  3. JakeThePeg

    JakeThePeg Active Member

    Messages:
    230
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #3
    Thanks for the quick response, although I couldn't get this code to work unfortunately...

    Not sure if this info has any bearing on things...

    http://codex.wordpress.org/Template_Tags/wp_list_authors
     
    JakeThePeg, Dec 10, 2008 IP
  4. mtsandeep

    mtsandeep Active Member

    Messages:
    218
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #4
    have you created an author page?
     
    mtsandeep, Dec 11, 2008 IP
  5. JakeThePeg

    JakeThePeg Active Member

    Messages:
    230
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #5
    JakeThePeg, Dec 12, 2008 IP
  6. JakeThePeg

    JakeThePeg Active Member

    Messages:
    230
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #6
    Since this code isn't working (and I'm hopeless at PHP) - how can I debug this piece of code? I think I should try and output the $results variable within the loop, I tried putting echo $results; under the foreach line but nothing printed (it's behind in the php file of this page http://www.helloelbow.com/the-crew/ )
     
    JakeThePeg, Dec 14, 2008 IP
  7. JakeThePeg

    JakeThePeg Active Member

    Messages:
    230
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #7
    Does anyone else have a suggestion for a loop that will list the Author IDs for all existing Wordpress authors?
     
    JakeThePeg, Dec 14, 2008 IP
  8. thefatwalletpublisher

    thefatwalletpublisher Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    This isn't completely what you require but may help you

    http:// wordpress.org /extend/ plugins/ author-listing/

    Just remove the spaces to get the link, I do not have enough posts to insert live links

    ATB George
     
    thefatwalletpublisher, Feb 26, 2009 IP