Add gravatar to author list

Basic setup

<?php

    $args = array( 'orderby' => 'nicename' );
    $users = get_users( $args ); 

    foreach ( $users as $user ) {
        $avatar = get_avatar( $user->ID, '80' );
        echo '<li><a href="' .
                $user->user_url .
            '">' .
                $avatar . '<br />' .
                $user->display_name .
            '</a></li>';
    }

 ?>

Excluding the Admin User

Either check in the foreach:

foreach ( $users as $user ) {
    if( ! in_array( 'administrator', $user->roles ) ) {
        // echo user list
    }
}

or if all other users are subscribers, include the role parameter as an argument for the user query:

$args = array(
    'orderby' => 'nicename',
    'role' => 'subscriber'
);

or, if you have but one (or few static) admin user, exclude him/her from the query by id:

$args = array(
    'orderby' => 'nicename',
    'exclude' => array( 1, 23 ) //adjust
);

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)