WordPress.org

Ready to get started?Download WordPress

Forums

How to list authors? (9 posts)

  1. ashbryant
    Member
    Posted 4 years ago #

    Hi,

    I'm working on a project at the moment that needs a section in the blogs sidebar that lists out the "Team" or authors and their job titles as a link to their author page. So it would look some thing like this...

    Mike - The Boss
    Ash - The Web Designer
    Simon - The Graphic Designer

    And so on.

    I have used <?php wp_list_authors('exclude_admin=1'); ?>, which list out all the authors, including admin even when changing 1 to 0 & back, but I can't grab any extra info from this call.

    Does anyone have any ideas on how to do this?

  2. MichaelH
    Member
    Posted 4 years ago #

    List users of blog

    <?php
    $blogusers = get_users_of_blog();
    if ($blogusers) {
    foreach ($blogusers as $bloguser) {
    $user = get_userdata($bloguser->user_id);
    //uncomment next line to see all values
    //echo "<pre>"; print_r($user); echo "</pre>";
    echo 'User ID ' . $user->ID . ' ' . $user->user_firstname . ' ' . $user->user_lastname ;
    }
    }
    ?>
  3. ashbryant
    Member
    Posted 4 years ago #

    Thanks MichaelH,

    But that's not what I'm after. I would like to be able for the code to do something like this.

    look at the list of the authors. List those names & add some of their profile info along with their name.

    Like this.

    Mike - The Boss
    Ash - The Web Designer
    Simon - The Graphic Designer

    The job title could be stored in the surname field maybe as it's not being used?

  4. ashbryant
    Member
    Posted 4 years ago #

    Sorry I have been dumb. That's great thanks.

  5. ashbryant
    Member
    Posted 4 years ago #

    MichaelH,

    Any way to exclude a author by id from that?

  6. MichaelH
    Member
    Posted 4 years ago #

    add something like this to exclude author id 1:

    if ($user->ID != '1' ) {
    echo 'User ID ' . $user->ID . ' ' . $user->user_firstname . ' ' . $user->user_lastname ;
    }
  7. Coloumbo
    Member
    Posted 4 years ago #

    Very usefull. Thank you very much :-)

    How about the list_authors() ? When it that one supposed to be used?

  8. Coloumbo
    Member
    Posted 4 years ago #

    And further more:

    I am trying to reach the value of the capabilities but its empty.

    Can you see what I've done wrong?

    <?php
    
    $blogusers = get_users_of_blog();
    
    if ($blogusers) {
    	foreach ($blogusers as $bloguser) {
    		$user = get_userdata($bloguser->user_id);
    		//uncomment next line to see all values
    		echo "<pre>"; print_r($user); echo "</pre>";
    
    		$user_cap = $user->wp_capabilities;
    
    			echo 'User ID ' . $user->ID . ' ' . $user->user_firstname . ' ' . 
    
    $user->user_lastname . ' ' . $user_cap[0];
    
    	}
    }
    
    ?>
  9. GandJ
    Member
    Posted 4 years ago #

    Hey MichaelH,

    Better you should use this below code instead of checking the staic condition by user_id is 1.

    Since you might have more than one admin also on your blog.

    $isadmin = $wpdb->get_results("SELECT count(*) as count from $wpdb->usermeta WHERE user_id = $user->ID and meta_value=10");
    if ($isadmin[0]->count == 0 ) {
    //uncomment next line to see all values
    //echo "
    <pre>"; print_r($user); echo "</pre>
    ";
    echo 'User ID ' . $user->ID . ' ' . $user->user_firstname . ' ' . $user->user_lastname ;
    }

Topic Closed

This topic has been closed to new replies.

About this Topic