Wordpress and Webdesign Forum go41 » WordPress Code Snippets

  1. adamwork
    Member

    I understand that you can use <?php list_authors(TRUE, TRUE, TRUE); ?> to display the list of all the authors on the site. But how would you go about setting up a grid with a picture of each author, their name, and a description?

    I'm already using user photo to grab their image, I'm just not sure how to loop this in a grid format...

    <h2>About the author</h2>

    <h4>">
    <?php the_author_firstname(); ?> <?php the_author_lastname(); ?>
    </h4>
    <div class="clearfix">
    <div class="post">
    <div class="right">"><?php userphoto_the_author_photo(); ?></div>

    <p><?php the_author_description(); ?></p>
    <p>/?author=<?php the_author_ID(); ?>">
    Read more articles by <?php the_author_firstname(); ?> <?php the_author_lastname(); ?>
    </p>
    <p> Total articles: <?php the_author_posts(); ?></p>

    Posted 1 year ago #
  2. list_authors is now wp_list_authors and loops in itself with some arguments you can set.
    So here you can't include the image of the 'user photo' plugin (userphoto_the_author_photo).

    You have to create a custom loop, a sample query for users you find here:
    List user sorted by last name: http://wordpress.org/support/topic/327359

    <?php
    $lastnames = $wpdb->get_col("SELECT user_id FROM $wpdb->usermeta WHERE $wpdb->usermeta.meta_key = 'last_name' ORDER BY $wpdb->usermeta.meta_value ASC");
      foreach ($lastnames as $userid) {
        $user = get_userdata($userid);
        $post_count = get_usernumposts($user->ID);
        $author_posts_url = get_author_posts_url($user->ID);
        echo '<li><a href="' . $author_posts_url . '">' . $user->user_firstname . ' ' . $user->user_lastname . '</a> (' . $post_count . ') </li>';
      }
    ?>

    try this query first, no image yet

    If you get a list of your users (authors), you should try something like

    <?php userphoto($user->ID); ?> or

    echo userphoto($user->ID);

    inside the above loop

    code above from: http://wordpress.org/extend/plugins/user-photo/

    If you want to display the user's photo in the sidebar, just get the user ID or object and pass it into userphoto() or userphoto_thumbnail()

    I would also have to try..

    EDIT:
    just found another code snippet:

    <?php
    $authors = $wpdb->get_results("SELECT ID from $wpdb->users " . ($exclude_admin ? "WHERE user_login <> 'admin' " : '') . "ORDER BY display_name");
    $author_count = array();
    echo "<ul>";
    foreach ( (array) $authors as $author ) {
            $author = get_userdata( $author->ID );
            $posts = (isset($author_count[$author->ID])) ? $author_count[$author->ID] : 0;
            $name = $author->display_name;
                    echo "<li>" . userphoto_thumbnail($author->ID, ' ', ' ', array(style => 'border:0')) . " " . $user->display_name . "</li>";
    
    echo "</ul>";
    
    }
    ?>

    you might just replace userphoto_thumbnail(.. with userphoto(.. in the code given
    source: http://www.sitepoint.com/forums/showthread.php?t=588271

    Posted 1 year ago #
  3. adamwork
    Member

    joern thanks for getting back. the top version works well, but displays the admin.

    the bottom version is good, but only displays the first name over and over again.

    Therefore, how can I include the exlude admin into the first one?
    also, where should I include the userphoto($user->ID); in the first set of code?

    thanks for your help

    Posted 1 year ago #
  4. no idea how to exclude the admin in top query, you could do something like this inside the loop, it will jump the author with id=1:

    if ( '1' == $author->ID ) { continue;}

    no idea again if following code will show the image and exclude author ID 1, just try

    <?php
    $lastnames = $wpdb->get_col("SELECT user_id FROM $wpdb->usermeta WHERE $wpdb->usermeta.meta_key = 'last_name' ORDER BY $wpdb->usermeta.meta_value ASC");
      foreach ($lastnames as $userid) {
    if ( '1' == $user->ID ) { continue;}
        $user = get_userdata($userid);
        $post_count = get_usernumposts($user->ID);
        $author_posts_url = get_author_posts_url($user->ID);
        $auth_img = userphoto($user->ID);
        echo '<li>' . $auth_img . '<br /><a href="' . $author_posts_url . '">' . $user->user_firstname . ' ' . $user->user_lastname . '</a> (' . $post_count . ') </li>';
      }
    ?>
    Posted 1 year ago #

RSS feed for this topic

Reply

You must log in to post.

Join us! or log in (lost password?):