Support » Fixing WordPress » Displaying list of author descriptions

  • Resolved caseydukes

    (@caseydukes)


    I had made a page template that displayed all blog authors with their name, avatar, bio, and link to their posts. It was working great until the blog was updated to 3.3. The name and bio were no longer displaying.

    This is what I was using:

    <?php
    $display_admins = true;
    $order_by = 'display_name'; // 'nicename', 'email', 'url', 'registered', 'display_name', or 'post_count'
    $role = ''; // 'subscriber', 'contributor', 'editor', 'author' - leave blank for 'all'
    $avatar_size = 64;
    $hide_empty = true; // hides authors with zero posts
    
    if(!empty($display_admins)) {
    	$blogusers = get_users('orderby='.$order_by.'&role='.$role);
    } else {
    	$admins = get_users('role=administrator');
    	$exclude = array();
    	foreach($admins as $ad) {
    		$exclude[] = $ad->ID;
    	}
    	$exclude = implode(',', $exclude);
    	$blogusers = get_users('exclude='.$exclude.'&orderby='.$order_by.'&role='.$role);
    }
    $authors = array();
    foreach ($blogusers as $bloguser) {
    	$user = get_userdata($bloguser->ID);
    	if(!empty($hide_empty)) {
    		$numposts = count_user_posts($user->ID);
    		if($numposts < 1) continue;
    	}
    	$authors[] = (array) $user;
    }
    
    echo '<ul class="contributors">';
    foreach($authors as $author) {
    	$display_name = $author['display_name'];
    	$description = $author['description'];
    	$avatar = get_avatar($author['ID'], $avatar_size);
    	$author_profile_url = get_author_posts_url($author['ID']);
    
    	echo '<li><h3>'.$display_name.'</h3><a href="', $author_profile_url, '">', $avatar , '</a><p>'.$description.'</p><p><a href="', $author_profile_url, '" class="contributor-link">➤ Posts by '.$display_name.'</a></p></li>';
    }
    echo '</ul>';
    ?>

    Changing

    $display_name = $author['display_name'];

    to

    $display_name = $author['data']->display_name;

    fixed the name problem, but I can’t figure out how to get the author bio (description) to display. It seems like it is just a matter or rewriting this line

    $description = $author['description'];

    …but I’ve tried different variations, and nothing seems to work. Help please!

Viewing 6 replies - 1 through 6 (of 6 total)
  • I think this is what you want:

    $description = get_userdata($author['ID'])->user_description;

    See the Notes after this Codex section:

    Function_Reference: get_userdata: Accessing_Usermeta_Data

    Yay! That worked. Thanks very much.

    this code has helped me A LOT.
    ive made a little tweak to it, to display pics of people who has posted OR commented.

    foreach ($blogusers as $bloguser) {
    	$user = get_userdata($bloguser->ID);
    	if(!empty($hide_empty)) {
    		$numposts = count_user_posts($user->ID);
    		$comments = get_comments('user_id='.$user->ID);
    		$comments_counted = count($comments);
    		if(($numposts < 1) AND ($comments_counted < 1)) continue;
    	}
    	$authors[] = (array) $user;
    }

    I’m trying to create an authors’ page that lists all authors’ full names, their bios, and their posts with links.

    Does anyone know how to modify the above code so that instead of creating a link to an author page it actually displays a list of posts?

    I found this, which shows how to list authors’ posts:
    http://wordpress.org/support/topic/list-authors-with-avatar-pic-and-last-posts

    All I need now effectively is to combine the two, but I don’t know how.

    Appreciate any help.

    @badgefarmer the code on the page you linked does just that.
    lists all authors, with their avatar and a list of posts.

    Sorry, maybe I wasn’t clear. I wanted to do that plus incorporate the list of author bios.

    Anyway, I experimented a bit with the code from this page and the one I linked to and worked it out. It’s working ok now.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Displaying list of author descriptions’ is closed to new replies.