Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

List of Author Boxes WordPress

  • SOLVED

Hi!

I want to have a page with a list of all the authors of the website. Instead of having just a list I want to have:

Image of the author (I'm using User Photo plugin not avatars)
Name of the author
Description of the author
Link to the author's archive of text


I don't want to list either the admin nor the contributors, just the authors.

I found this code, but I coulnd't make it work:
http://bavotasan.com/tutorials/how-to-display-an-author-list-with-avatars-in-wordpress/

Thanks!

Answers (2)

2010-02-26

Dan Fraticiu answers:

Put this into your function.php

function authors_list_shortcode_handler($atts, $content=null){

global $wpdb;

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

$content = '';
foreach($authors as $author){

$content .='<div id="colaborador">';

$content .= userphoto($author->ID);
$content .= '<div id="titulocolaborador">'.get_usermeta($author->ID, 'first_name').' '.get_usermeta($author->ID, 'last_name').'</div>';

$content .= '<div id="textocolaborador">'.get_usermeta($author->ID, 'description').'</div>';

$content .= '<a href="'.get_author_posts_url($author->ID, $author->user_nicename).'">Link</a>';

$content .= '</div>';
}

return $content;

}
add_shortcode('authors_list','authors_list_shortcode_handler');



Then use this [authors_list] where you wnat to display the list.

I'm don't know if the photo will work, I haven't test it as I don't have that plugin installed but everything else shold be fine.


Olivia comments:

Hi Dan,

Thanks for answering.
This is giving error:
.userphoto

Everything else work great
I'm using the plugin because some of the writers prefer to email their picture to me than to create their avatar by themselves. Can you think in how to solve this?


Dan Fraticiu comments:

I've updated the code, and I tested it. You should have no more problems.


Olivia comments:

Thanks Dan,

It works perfectly!

2010-02-26

Nathaniel Usarzewicz answers:

So, in function.php copy/paste this code:


function my_list_authors() {
global $wpdb;

$authors = $wpdb->get_results("SELECT * from $wpdb->usermeta WHERE meta_key = 'wp_capabilities' AND meta_value = 'a:1:{s:6:\"author\";b:1;}'");

foreach ( (array) $authors as $author ) {
$author = get_userdata( $author->user_id );
$userlevel = $author->wp2_user_level;

$name = "$author->first_name $author->last_name";
$the_description = $author->description;
$author_id = $author->ID;

$file = get_option('home') . '/';
$the_link .= $file . '?author=' . $author_id;

?><li><?php echo '<a href="' . $the_link . '" title="' . $name . '">';?><?php echo userphoto($author_id, '', '', array(style => 'width:100px;height:100px;'), get_template_directory_uri() . '/default-avatar.gif'); ?><br /><span class="authors_displayname"><?php echo $name; ?></span></a><br /><?php echo $the_description; ?></li>
<?php
}
}


Then create page template ([[LINK href="http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates"]]how-to on Codex[[/LINK]]) and within WordPress loop paste this function:


<ul>
<?php my_list_authors(); ?>
</ul>


This will display all authors (people with author rank) from your WordPress with userphoto, name, description and it will all be wrapped into link to author's archive, and it will also display default avatar from your template folder :)


Olivia comments:

Hi Nathaniel,
Thanks for your response.
I can't make your code work.
The page is blank: http://www.olivialiendo.com/marcapasos/colaboradores-2/


Nathaniel Usarzewicz comments:

Then try this, find:

'a:1:{s:6:\"author\";b:1;}

and change to:

'a:1:{s:10:\"author\";b:1;}

If this doesn't work, please take a look at your database -search usermeta table, look for wp_capabilities like this a:1:{s:6:\"author\";b:1;} - that 'author' part is what really matters, when you find it, copy and paste into the code as I said (replace a:1:{s:6:\"author\";b:1;}) with it, and it should work.


Olivia comments:

Thanks for your help Nathaniel,
I'll have you in my mind next time that I need some help.