The MU forums have moved to WordPress.org

List Authors (23 posts)

  1. maxaud
    Member
    Posted 5 years ago #

    I'm using this code in my sidebar on a regular wordpress to list authors:

    <h2>Link list of authors:</h2>
    <ul>
        <?php
        $order = 'user_nicename';
        $user_ids = $wpdb->get_col("SELECT ID FROM $wpdb->users ORDER BY $order"); // query users
        foreach($user_ids as $user_id) : // start authors' profile "loop"
        $user = get_userdata($user_id);
        ?>
        <li><?php echo '<a href="' . $user->user_url . '">' . $user->display_name . '</a>'; ?></li>
        <?php
        endforeach; // end of authors' profile 'loop'
        ?>
    </ul>

    but on a WordPress MU theme it lists all blogs users..

    How do I restrict it to use the current blogs authors/contributors?

    An example of what I'm trying to do can be seen at myfhablog.com where we've got a list of authors with gravatars that are randomized.

    Thanks in advance to those that help me shed some light on my poor php/sql skills.

  2. dsader
    Member
    Posted 5 years ago #

  3. tdjcbe
    Member
    Posted 5 years ago #

    Doesn't mu have a specific get_blog_users or something along those lines as well? I can't check from here to make sure.

  4. dsader
    Member
    Posted 5 years ago #

    WP and WPMU share the same
    $users = get_users_of_blog($blog_id);
    from wp-includes/user.php which will return ID and the email so gravatars should be a snap to add. A linking url to user sites if no author page will need to be added as well.

  5. indojepang
    Member
    Posted 5 years ago #

    Hi, i've managed to do this. you can see it here => http://jawerkotok.terminalmusik.com/ on the BIO tab.

    One problem though.. how do exclude me (A-Team -> site Admin)?

    here's the code:

    <?php

    // Get the authors from the database ordered by user nicename
    global $wpdb;
    $query = "SELECT ID, user_nicename from $wpdb->users ORDER BY user_nicename";
    $author_ids = $wpdb->get_results($query);

    // Loop through each author
    foreach($author_ids as $author) :

    // Get user data
    $curauth = get_userdata($author->ID);

    // If user level is above 0 or login name is "admin", display profile
    if($curauth->user_level > 0 || $curauth->user_login == 'admin') :

    // Get link to author page
    $user_link = get_author_posts_url($curauth->ID);

    // Set default avatar (values = default, wavatar, identicon, monsterid)
    $avatar = 'wavatar';
    ?>

    <li class="bio">

    " title="<?php echo $curauth->display_name; ?>">
    <?php echo get_avatar($curauth->user_email, '80', $avatar); ?>

    <h3 class="post-title">
    " title="<?php echo $curauth->display_name; ?>"><?php echo $curauth->display_name; ?>
    </h3>
    <?php $meta = call_usermeta(); print_r($meta->posisi);?>
    <?php $meta = call_usermeta(); print_r($meta->birthdate);?>
    <p>
    <?php echo $curauth->description; ?>
    </p>

    <?php endif; ?>

    <?php endforeach; ?>

  6. dsader
    Member
    Posted 5 years ago #

    $site_admin = "YOUR ID HERE";
    $query = "SELECT ID, user_nicename from $wpdb->users WHERE ID != '$site_admin'
     ORDER BY user_nicename";
  7. indojepang
    Member
    Posted 5 years ago #

    Wow!! Thank's a lot dsader!! :D i'll try this

  8. indojepang
    Member
    Posted 5 years ago #

    it works great! :D

  9. maxaud
    Member
    Posted 5 years ago #

    Thanks for the reply guys.
    I didn't realize my other post actually posted. It was giving me errors when I posted it.

    I'll try these out and report back.

    Thanks again!

  10. maxaud
    Member
    Posted 5 years ago #

    Would there be a way to order by most recent to post?

  11. dsader
    Member
    Posted 5 years ago #

    Given the querries in the context of the Author List above? No.

  12. maxaud
    Member
    Posted 5 years ago #

    Thanks guys, I was able to get what I needed.
    How would I add:

    - link to each users rss feed
    - link to each users lists of posts

    thanks!

  13. dsader
    Member
    Posted 5 years ago #

  14. maxaud
    Member
    Posted 5 years ago #

    ok, I put the code in at:
    http://blogs.wannanetwork.com/ShortSales/

    for some reason it shows a different amount of people each time the page is loaded.

    My code is as follows:

    <?php
    
    		// Get the authors from the database ordered randomly
    		global $wpdb;
    		$query = "SELECT ID, user_nicename from $wpdb->users WHERE ID != '4' ORDER BY RAND() LIMIT 50";
    		$author_ids = $wpdb->get_results($query);
    
    		// Loop through each author
    		foreach($author_ids as $author) :
    
    		// Get user data
    		$curauth = get_userdata($author->ID);
    
    		// If user level is above 1 or login name is "admin", display profile
    		if($curauth->user_level > 1 || $curauth->user_login == 'admin') :
    
    		// Get link to author page
    		$user_link = get_author_posts_url($curauth->ID);
    
    		// Set default avatar (values = default, wavatar, identicon, monsterid)
    		$avatar = 'default';
    	?>
    
    	<table>
    		<tr>
    			<td>
    				<a href="<?php echo $curauth->user_url; ?>"><?php echo get_avatar($curauth->user_email, '50'); ?></a>
    			</td>
    			<td>
    				<a href="<?php echo $curauth->user_url; ?>" title="<?php echo $curauth->display_name; ?>"><?php echo $curauth->display_name; ?></a><br />
    				<?php echo $curauth->description; ?>
    			</td>
    		</tr>
    	</table>
    	<?php endif; ?>
    	<?php endforeach; ?>
  15. maxaud
    Member
    Posted 5 years ago #

    Would anyone know why it would show a different ammount of people each time the page is loaded?

  16. dsader
    Member
    Posted 5 years ago #

    remove
    if($curauth->user_level > 1 || $curauth->user_login == 'admin') :
    and

    <?php endif; ?>

    That line is not doing what you expect it to do. $curauth is not global $current_user, therefore doesn't have a user_level.

    You may need new test for logged in as admin.

    get_currentuserinfo();

    before

    if($user_level etc etc

  17. maxaud
    Member
    Posted 5 years ago #

    dsader,
    I removed that and it shows all users from all blogs.
    How do I show only authors of the current blog?

  18. dsader
    Member
    Posted 5 years ago #

    Why $query then?

    Use existing template tags.

    http://mu.wordpress.org/forums/topic.php?id=10171

  19. maxaud
    Member
    Posted 5 years ago #

    Ok, I found that my 'LIMIT 50' was causing the issues.
    I think the above query was getting all users of my wordpress MU and then limiting that to 50 people.
    Then when it had those 50 people, it only showed the authors who are part of that current blog.
    Since I was set to random it was a different number from that blog in the 50 results each time.
    This makes sense, seeing as the user base of my MU has been growing and the authors on the sidebar were showing fewer and fewer each time.
    I fixed it by taking out the limit 50 but now how would I limit the number of users knowing what I know now?

  20. maxaud
    Member
    Posted 5 years ago #

    dsader,
    I needed to pull user information for avatars, email, url, etc.

    As seen on mu here:
    http://blogs.wannanetwork.com/ShortSales/

    On a regular wordpress install here:
    http://www.myfhablog.com/

  21. fondalashay
    Member
    Posted 4 years ago #

    Hello! I have the code below generating a contributors page. The problem is that it only list the admin, how do i make it list everyone?

    <?php
    
    // Get the authors from the database ordered by user nicename
    global $wpdb;
    $query = "SELECT ID, user_nicename from $wpdb->users ORDER BY user_nicename";
    $author_ids = $wpdb->get_results($query);
    
    // Loop through each author
    foreach($author_ids as $author) :
    
    // Get user data
    $curauth = get_userdata($author->ID);
    
    // If user level is above 0 or login name is "admin", display profile
    if($curauth->user_level > 1) :
    
    // Get link to author page
    $user_link = get_author_posts_url($curauth->ID);
    
    // Set default avatar (values = default, wavatar, identicon, monsterid)
    $avatar = 'wavatar';
    ?>
    
    <?php wp_list_authors ?>
    <small style="visibility:hidden; font-size:1px;">Line Break</small>
    <?php echo get_avatar( get_the_author_email(), '50' ); ?>
    <p><b><?php the_author_link(); ?></b> <small>(<?php the_author_posts(); ?> Articles)</small></p>
    <p><?php the_author_description(); ?></p>
    
    <?php endforeach; ?>

    Thanks!

  22. tdjcbe
    Member
    Posted 4 years ago #

    Why do I get the feeling that you;re doing this on blog 1 and only the admin have access to that blog? That's the first thing that comes to mind.

    Please remove these lines and see what happens please:

    if($curauth->user_level > 1) :
    <?php endforeach; ?>

  23. fondalashay
    Member
    Posted 4 years ago #

    @tbjcbe Thanks for the quick reply!!

    i removed if($curauth->user_level > 1) :

    but when i remove <?php endforeach; ?> it wont let the page load.

    with just the first piece out then it loads the admin profile 5 times, I have atm 1 admin and 4 contributors.

    any other ideas?

    Thanks!! :)

About this Topic

  • Started 5 years ago by maxaud
  • Latest reply from fondalashay