WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] List authors is listing admin multiple times (19 posts)

  1. fondalashay
    Member
    Posted 4 years ago #

    Hello!

    I am working on a author page that will list my authors along with some info on them. Tho code is partially working. The problem is now that i have 5 "users" and it recognizes that - but it adds the profile of the admin 5 times instead.

    <?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);
    
    // 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; ?>

    Any help would be greatly appreciated!!

  2. MichaelH
    Member
    Posted 4 years ago #

    Don't know why you would need this:

    <?php wp_list_authors ?>

    Can only guess that's causing the admin user to be listed and you have it in a foreach loop.

  3. fondalashay
    Member
    Posted 4 years ago #

    I took it out and noting changed.

    Here is a link to the site not sure if that will help! it is just on a test server now, but i really need to figure this out bc it is moving soon to the real deal!

    any other ideas?
    Thanks!

  4. MichaelH
    Member
    Posted 4 years ago #

    Please paste all the code from the theme template file that is displaying those posts into a pastebin, such as wordpress.pastebin.ca, and report the link back here. Maybe someone can spot your problem. Thanks.

  5. fondalashay
    Member
    Posted 4 years ago #

    Pastebin link: http://wordpress.pastebin.ca/1656467

    thanks!

  6. Kevin Kwok
    Member
    Posted 4 years ago #

    here you go this is what i used on my page
    <?php wp_list_authors('show_fullname=1&exclude=admin'); ?>
    works like a charm , let me know if you have any problems

  7. fondalashay
    Member
    Posted 4 years ago #

    queesy,

    thanks! I have had that previously. I am looking for a more beefed up version. I am needing the avatar and authors bio with it. Not just a list of names!

    You can see here what i am going for and my problem.

    thanks for the help!

  8. MichaelH
    Member
    Posted 4 years ago #

    That template you are using looks like it was intended to be a Page template that displayed the title/content of a Page and listed the authors.

    So each user was being list over again because of a loop. I've commented out (with a //) the lines you don't need. You may want to uncomment (delete the //) this line <?php //include (TEMPLATEPATH . "/breadcrumb.php"); ?> to show your breadcrumb.

    http://wordpress.pastebin.ca/1656467

  9. fondalashay
    Member
    Posted 4 years ago #

    hey! thanks! the pastebin looks exactly the same to me... i might be missing something.. is there something i need to click to see what you have done? I have never used pastebin before.

    I am so sorry... you are being so helpful.. and i am just not understanding.. i am very sorry. I am still new with php and wordpress and well codes in general.

  10. MichaelH
    Member
    Posted 4 years ago #

    Sorry, I used your pastebin link. It should be http://wordpress.pastebin.ca/1656539

  11. fondalashay
    Member
    Posted 4 years ago #

    cool! well it is a start! it looks like this. so it is getting the different authors.. just in a odd way :P

    Since this is so troublesome.. is there a way i can just manually link in the profiles?

    like this for example (just my thoughts.. i know it is not valid)

    <?php echo get_avatar(admin, '50' ); ?>
    <p><b><?php the_author_link(); ?></b> <small>(<?php the_author_posts(); ?> Articles)</small></p>
    <p><?php the_author_description(); ?></p>
    <br />
    <?php echo get_avatar(cynthia, '50' ); ?>
    <p><b><?php the_author_link(); ?></b> <small>(<?php the_author_posts(); ?> Articles)</small></p>
    <p><?php the_author_description(); ?></p>

    If something like this would be easier.. i have no problem adding this to the code when i have a new author.. as it is not going to be very often that I add one.

    thanks again for all your help!

  12. MichaelH
    Member
    Posted 4 years ago #

    Oh darn, delete this line:

    echo "<pre>"; print_r($author_ids); echo "</pre>";

    Related:
    Author Templates

  13. fondalashay
    Member
    Posted 4 years ago #

    ok looks like this now.

  14. MichaelH
    Member
    Posted 4 years ago #

  15. fondalashay
    Member
    Posted 4 years ago #

    oh AMAZING! you are my new hero!

    thank you so much! the girls are going to be soo happy!

  16. Mark / t31os
    Moderator
    Posted 4 years ago #

    wp_list_authors is a hell of a lot slower then get_users_of_blog.. :(

    Which is somewhat disappointing because get_users_of_blog actually returns more useful data..

    wp_dropdown_users was slightly slower then get_users_of_blog when preg_matched to extract IDs..

    Havn't tested, but you may wish to look at.
    http://codex.wordpress.org/Template_Tags/the_author_meta
    ..for grabbing user data, that way you specify the fields you want, rather then grabbing a complete user object with all fields.

    It may be slower (could also be faster), no idea, i didn't test for that, was simply curious of speed comparison between wp_list_authors,get_users_of_blog and wp_dropdown_users.

    Good call on get_users_of_blog...

  17. MichaelH
    Member
    Posted 4 years ago #

    wp_list_authors is a hell of a lot slower then get_users_of_blog.. :(

    Is that right t31os_?

  18. Mark / t31os
    Moderator
    Posted 4 years ago #

    Yes, i'd imagine it's related to the queries used by wp_list_authors ..
    wp-includes/author-template.php: Lines 259 - 265

    /** @todo Move select to get_authors(). */
    	$authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users " . ($exclude_admin ? "WHERE user_login <> 'admin' " : '') . "ORDER BY display_name");
    
    	$author_count = array();
    	foreach ((array) $wpdb->get_results("SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE post_type = 'post' AND " . get_private_posts_cap_sql( 'post' ) . " GROUP BY post_author") as $row) {
    		$author_count[$row->post_author] = $row->count;
    	}

    Looks like a loop of queries, so essentially several queries, compare that to the get_users_of_blog query..
    wp-includes/user.php: Line 281

    $users = $wpdb->get_results( "SELECT user_id, user_id AS ID, user_login, display_name, user_email, meta_value FROM $wpdb->users, $wpdb->usermeta WHERE {$wpdb->users}.ID = {$wpdb->usermeta}.user_id AND meta_key = '{$wpdb->prefix}capabilities' ORDER BY {$wpdb->usermeta}.user_id" );

    1 query, so less extensive..

  19. Richard Sweeney
    Member
    Posted 4 years ago #

    I'm sorry to post here, but I can't think of anywhere better!

    The code at http://wordpress.pastebin.ca/1656804 works great - but what I'd like to do is to actually list the posts of each author, not just the number of posts.

    Also - is there a way to exclude the admins from the query, or to specify a user ID to omit?

    Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic