When you have that much code to output concatenating it into one string like that makes it very difficult to read for others and yourself, also, to debug when things go wrong.
Try this method for concatenating your output,
$blogusers = get_users('role=contributor&orderby=display_name');
foreach ($blogusers as $user) {
$name = $user->display_name;
$url = get_author_posts_url($user->ID, $author_nicename);
$class = get_user_meta($user->ID, 'people_lists_class', true);
$title = get_user_meta($user->ID, 'people_lists_title', true);
$desc = get_user_meta($user->ID, 'people_lists_title', true);
$avatar = get_avatar($user->ID, 50);
$html="<li class="person member">";
$html .= '<a href="' . $url . '"> <div class="user-thumbnail alignleft">' . $avatar . '</div></a>';
$html .= '<a href="' . $url . '"><h5 class="user-name user-info">' $name . ($class ? ', ' . $class : '') . '</h5></a>';
$html .= '<p class="user-title user-info">' . $title . '</p>';
$html .= '<p class="user-bio user-info">' . $desc . '</p>';
$html .= '<a href="' . $url . '"><p class="user-permalink user-info"> View articles by ' . $name . '</p></a>';
$html .= '<div class="clear"></div></li>';
echo $html;
}
So much nicer eh?
We store all of the information we need in variables that we pass along to our $html
which means we can re-use the same variables over and over without making our code unnecessarily bloated with long verbose functions and function arguments to retrieve data. Not only that but its easier to read and if something goes wrong you’ll find it much easier to debug your code than if you were doing it the other way around.
The particular statement which conditionally shows the comma ( ,
) is;
//shortened the line for brevity
$name . ($class ? ', ' . $class : '') ... etc
So $name
will show AND IF a value is held within people_lists_class
it will print to screen the comma followed by whatever is in the class name field e.g. , class_name_here_bla_bla
In the end looking something like,
Bob Brown, Lowerclass Citizen