Displaying a Users Information

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

<div id="entry-author-info">

<div id="author-avatar">

<?php echo get_avatar(get_the_author_meta('user_email')); ?>

<div id="author-description">

<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(); ?> &rarr;</a>

Figure 10-2. The user information as displayed in the Twenty Ten theme

Was this article helpful?

0 0

Post a comment