Support » Fixing WordPress » Outputting categories authors have written in as class

  • OK, I have a very specific question that I hope someone can shed some light on.

    I have a list of authors outputting using the following code

    $display_admins = false;
    $order_by = 'post_count'; // 'nicename', 'email', 'url', 'registered', 'display_name', or 'post_count'
    $role = ''; // 'subscriber', 'contributor', 'editor', 'author' - leave blank for 'all'
    $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.'&order='.'DESC');
    $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['data']->display_name;
    	$avatar = get_wp_user_avatar($author['ID'], 'medium');
    	$author_profile_url = get_author_posts_url($author['ID']);
    	$filter = get_userdata($author['ID'])->yim;
    	echo '<li><div class="home ', $filter,'  "><div class="feature-image"><a href="', $author_profile_url, '">', $avatar , '</a></div>
    	<div class="post-title"><a href="', $author_profile_url, '"><h3>', $display_name, '</h3></a></div>
    echo '</ul>';

    (I got this from another support topic and tweaked it, although I can’t remember where)

    At the moment, the $filter variable is just a string I enter in the ‘Yahoo IM’ profile box. I’d like this to actually be a list of the categories (as classes or slugs) that the author has posted in.

    I essentially want to be able to filter the authors by category that they have posted in, and the filter I’m using operates using the class, so outputting the categories in to the class of the markup is what I’m after.

    Any suggestions gratefully received!

  • The topic ‘Outputting categories authors have written in as class’ is closed to new replies.