WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am attempting to display the authors of my site in a jquery carousel but for some reason my images are outputted outwith the li tags and I don't know why.



function contributors() {
    global $wpdb;

    $authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users ORDER BY display_name");

    foreach($authors as $author) {
        // display user image for each author
        echo '<li class="author" id="author-'.$author->ID.'">'.userphoto($author->ID).'</li>';

Template File

<?php while ( have_posts() ) : the_post(); ?>

    <div id="authorlist"><ul id="authorcarousel"><?php contributors(); ?></ul></div>

<?php endwhile; // end of the loop. ?>


<div id="authorlist">
    <ul id="authorcarousel">
        <img src="/wordpress/wp-content/uploads/userphoto/1.jpg" alt="admin" width="143" height="150" class="photo" />
        <li class="author" id="author-1"></li>
        <img src="/wordpress/wp-content/uploads/userphoto/3.png" alt="" width="128" height="128" class="photo" />
        <li class="author" id="author-3"></li>
        <img src="/wordpress/wp-content/uploads/userphoto/2.png" alt="" width="128" height="128" class="photo" />
        <li class="author" id="author-2"></li>

What I am aiming for is the image to be outputted between the li tags.

A bonus question if someone knows the answer - how to edit the query so that only authors are displayed and not site admins? I tried adding a WHERE clause to the query but it didn't work.

Any help is much appreciated as I am a WordPress n00b.

share|improve this question

You should be using get_users() - this will perform your query and also allow you to limit by role.


userphoto isn't a WordPress function, but get_avatar() is: http://codex.wordpress.org/Function_Reference/get_avatar

Just check out the Codex examples and you should be able to modify to suit your needs!

-- UPDATE -- I reread and realized maybe userphoto is coming from another plugin - yes? If so, check if the result of that function echos the result. If so, you will need to change that part to:

echo '<li class="author" id="author-'.$author->ID.'">';
echo '</li>';
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.