To display a user's information inside the Loop, you don't need to find their user ID; all the user functions will assume that you're talking about the current post author and fill in the ID automatically.
You can use the the_author_meta() function to display user information. There's also get_the_author_meta(), which returns information for use in PHP rather than displaying it to the screen. Listing 10-2 shows how to create a footer for posts in a multi-author blog that displays the author's avatar, display name, and bio. This code should be placed in a theme's single.php file somewhere after the post content. Figure 10-2 shows how the resulting author information block appears in the Twenty Ten theme.
Listing 10-2. Displaying user information in a post footer
<?php echo get_avatar(get_the_author_meta('user_email')); ?>
<h2>About <?php the_author(); ?></h2> <?php the_author_meta('description'); ?> <div id="author-link">
<a href="<?php echo get_author_posts_url( $authordata->ID ); ?>" title="View all posts by <?php get_the_author(); ?>">
View all posts by <?php the_author(); ?> →</a>
Was this article helpful?