<?php
/*
Template Name: All Authors Template (WP2)
*/

/*
All Authors WordPress Page template by Kaf Oseo (http://szub.net/)
Version 2.1 - for WordPress 2.0 and above.

The All Authors Page template is based structurally on the WordPress
Default (Kubrick) Page template. It may require changes to layout to
work with other themes.

The template is commented throughout to explain the various elements
and provide detailed *clues* on modifying it.

A few notes:

1. My comments are for the most part 'tagged' off above the element
   described in their own php tags (<?php ... ?>. Most reference the
   first line of code (mainly an if statement), and then explain it.
   This should make it easier to remove the comments once everything
   is as you like it (though you can certainly leave them).

2. You probably don't want to display some bit of user info if a user
   does not fill that field out in their profile. That's why you find
   a lot of the script embedded in PHP *if* statements. So:

        <?php if($user->aim) : ?>
        AIM screen name: <?php echo $user->aim; ?>
        <br />
        <?php endif; ?>

   tests whether the AIM field has been filled in. If not (i.e. it's
   empty) it returns a false response, and won't display that line.

3. By default the header for each author (their name) is placed in an
   <h3> and given a CSS class of "author-profile".
*/
?>
<?php get_header
(); ?>

<div id="content" class="narrowcolumn">

    <h2>Author Profiles:</h2>
<?php
    
/*
    Set the $order variable to whatever you want to sort the authors'
    list on. You can use any users table column name; examples are:
    'ID', 'user_nicename', 'user_login', 'user_url', 'display_name',
    and 'dateYMDhour' (registration date).
    */
?>
<?php
    
global $wpdb$table_prefix// set global WP vars needed for script

    
$order 'user_nicename'// set order for users table query
    
$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); // retrieve author (i.e. user) details
    
$level $table_prefix 'user_level'// set 'user_level' usermeta meta_key record
    
$user->user_level $user->$level// assign 'user_level' property to $users
    
$role $table_prefix 'capabilities'// set 'role' usermeta table meta_key record
    
$user->role array_keys($user->$role); // assign 'role' property to $user
    
$user->role $user->role[0]; // make sure $user->role is not an array
?>
<?php
    
/*
    This is the authors' profile 'loop'. It displays info from the
    profile for every author, along with a few bits of other author-
    related data. Feel free to add, subtract, change layout; whatever
    you'd like.

    These 'tags' will display "publically accessable" user info; what
    is displayed by each is hopefully self-explanatory:

        <?php echo $user->aim; ?>
        <?php echo $user->description; ?>
        <?php echo $user->display_name; ?>
        <?php echo $user->first_name; ?>
        <?php echo $user->jabber; ?>
        <?php echo $user->icq; ?>
        <?php echo $user->ID; ?>
        <?php echo $user->last_name; ?>
        <?php echo $user->msn; ?>
        <?php echo $user->nickname; ?>
        <?php echo $user->role; ?>
        <?php echo $user->user_email; ?>
        <?php echo $user->user_level; ?>
        <?php echo $user->user_login; ?>
        <?php echo $user->user_nicename; ?>
        <?php echo $user->user_registered; ?>
        <?php echo $user->user_url; ?>
        <?php echo $user->yim; ?>
    */
?>
<?
    
/*
    if(('admin' != $user->user_login) && ($user->wp_user_level > 0)) :
    Tests for accounts that are not 'admin' or above 'subscriber' role.

    To display the admin account, comment out or remove the first 'if'
    line and uncomment the one right after it.

    The additional variations for the if statement listed below can be
    used if you want to check whether the user is assigned the role of
    'author', or author/contributor.

    Default roles you can work with here are:

        subscriber
        contributor
        author
        editor
        administrator

    If you're using a plugin that lets you create custom roles, these
    should work with it as well.

    Finally, if you want to display absolutely every user on your blog,
    use something like:

        if( $user->user_login ) :

    */
?>
<?php
    
if( ('admin' != $user->user_login) && ($user->user_level 0) ) :
    
//    if( $user->user_level > 0 ) : // show all users above the role of 'subscriber'
    //    if( $user->role == 'author' ) : // show only users with a role of 'author'
    //    if( ($user->role == 'author') || ($user->role == 'contributor') ) : // show users with role of 'author' or 'contributor'
?>

    <h3 id="user-<?php echo $user->ID?>" class="author-profile"><?php echo $user->first_name?> <?php echo $user->last_name?></h3>

<?php
    
/*
    Tests for and displays an author image. IMG element is assigned
    the CSS class 'author-image'.

    Change $image_dir to directory used to store your author images;
    start from blog root (example: 'wp-content/images'). Filename is
    based on user_nicename (ex: user login 'Kaf Oseo' = 'kaf-oseo')
    and 'jpg' file extension. Change $image_file the $author_image
    variables if you want to use another user profile element (such
    as user_nickname) or image type.
    */
    
?>
    <?php
    $image_dir 
'images'// directory where author images reside
    
$image_file $user->user_nicename// format for image name
    
$image_ext 'jpg'// author image extension

    
$image_path trim($image_dir'/') . '/' $image_file '.' $image_ext;
    if(
file_exists(ABSPATH $image_path)) :
        
$author_image =    get_bloginfo('home') . '/' $image_path;
?>
    <img class="user-image" src="<?php echo $author_image?>" alt="<?php echo $user->display_name?>" title="<?php echo $user->display_name?>" />
<?php endif; ?>

<?php
    
/*
    if($user->description)
    Tests for and displays user description (i.e. Profile).
    */
?>

<?php if($user->description) : ?>
    <p>
    <strong>Profile:</strong>
    <br />
<?php echo $user->description?>
    </p>
<?php endif; ?>

    <p>
<?php
    
/*
    if(get_usernumposts($user->ID) > 0)
    Tests for and displays post count and link to posts for author.
    */
?>
<?php 
if(get_usernumposts($user->ID) > 0) : ?>
    Number of posts: <a href="<?php get_author_link(true$user->ID"$user->user_nicename"); ?>"><?php echo get_usernumposts($user->ID); ?></a>
    <br />
<?php endif; ?>

<?php
    
/*
    if($user->user_email)
    Tests for and displays email; uses WP's antispambot() function
    to encode the address so it's displayed in browser but not read
    by emailbots.
    */
?>
<?php 
if($user->user_email) : ?>
    Email address:
    <a href="mailto:<?php echo antispambot($user->user_email1); ?>"><?php echo antispambot($user->user_email); ?></a>
    <br />
<?php endif; ?>

<?php
    
/*
    if($user->user_url && !('http://' == $user->user_url))
    Tests for and displays web site url if one exists and isn't just a "http://" with no
    actual url.
    */
?>
<?php 
if($user->user_url && !('http://' == $user->user_url)) : ?>
    Web site: <a href="<?php echo $user->user_url?>"><?php echo $user->user_url?></a><br />
    <?php endif; ?>

<?php
    
/*
    if($user->aim)
    Tests for and displays AIM screen name.

    Those that follow do same for Yahoo ID, Jabber/Google, MSN ID and ICQ number (last two
    are no longer available in the default User Profile listings in WordPress 2.0, but are
    retained here for legacy purposes).
    */
?>
<?php 
if($user->aim) : ?>
    AIM screen name: <?php echo $user->aim?>
    <br />
<?php endif; ?>

<?php if($user->yim) : ?>
    Yahoo ID: <?php echo $user->yim?>
    <br />
<?php endif; ?>

<?php
    
/*
    Jabber/Google ID is an email addy, so it's filtered through antispambot()
    */
?>
<?php 
if($user->jabber) : ?>
    Jabber/Google ID: <?php echo antispambot($user->jabber); ?>
    <br />
<?php endif; ?>

<?php if($user->msn) : ?>
    MSN ID: <?php echo $user->msn?>
    <br />
<?php endif; ?>

<?php if($user->icq) : ?>
    ICQ number: <?php echo $user->icq?>
    <br />
<?php endif; ?>

    </p>

<?php
    
endif; // end of admin and user_level test
    
endforeach; // end of authors' profile 'loop'
?>

</div>

<?php get_sidebar(); ?>

<?php get_footer(); ?>