Blog / WordPress/ WordPress Author Information: A Guide to Core Functions and Advanced Lists

WordPress Author Information: A Guide to Core Functions and Advanced Lists

WordPress 作者信息调用指南:从基础函数到高级列表

When building a multi-author blog or content-driven website, displaying author information is key to fostering community and content credibility. WordPress provides a rich set of Template Tags for retrieving author data. This guide systematically introduces these functions and explains how to use them to display author names, contact details, and generate author lists.

Core Author Information Functions

The following functions are typically used inside The Loop to retrieve information about the current post's author.

<?php the_author(); ?> // Displays the author's public display name.
<?php the_author_description(); ?> // Displays the author's biographical info.
<?php the_author_firstname(); ?> // Displays the author's first name.
<?php the_author_lastname(); ?> // Displays the author's last name.
<?php the_author_nickname(); ?> // Displays the author's nickname.
<?php the_author_ID(); ?> // Displays the author's user ID.
<?php the_author_email(); ?> // Displays the author's email (privacy note).
<?php the_author_url(); ?> // Displays the author's website URL.
<?php the_author_posts(); ?> // Displays the author's total published post count.
<?php the_author_posts_link(); ?> // Outputs a link to the author's archive page.

Important Notes & Updates

  • Deprecated Functions: Functions like the_author_login(), the_author_icq(), the_author_aim(), the_author_yim(), and the_author_msn() are deprecated in modern WordPress. Custom contact info is now typically stored as User Meta.
  • Custom Contact Information: To display custom fields (e.g., WeChat, QQ), use get_the_author_meta(). For example: <?php echo get_the_author_meta('wechat'); ?>.
  • Link Function: The the_author_link() function is also obsolete. The standard approach is to manually create a link using the_author() and the_author_url().

Generating Author Lists

To display a list of all authors in a sidebar or dedicated page, use the following function.

wp_list_authors()

This is the currently recommended function for generating a site author list. If an author has published posts, their name links to their archive.

<?php
wp_list_authors(array(
    'optioncount'   => false, // Show post count? true/false
    'exclude_admin' => true,  // Exclude admin? true/false
    'show_fullname' => false, // Show full name? Otherwise nickname.
    'hide_empty'    => true,  // Hide authors with zero posts.
    'feed'          => '',    // Text for RSS link (e.g., 'RSS').
    'feed_image'    => '',    // Image URL for RSS link (overrides 'feed').
));
?>

Deprecated: list_authors()

The list_authors() function is similar but deprecated. Use wp_list_authors() instead.

Practical Example: Displaying Author Info in a Theme

Here is example code for an author bio section in single.php or content.php:

<div class='author-bio'>
    <?php echo get_avatar(get_the_author_meta('ID'), 80); ?>
    <h3>About <?php the_author(); ?></h3>
    <p><?php the_author_description(); ?></p>
    <p>
        Posts: <?php the_author_posts(); ?> |
        <a href='<?php echo esc_url(get_author_posts_url(get_the_author_meta('ID'))); ?>'>View all posts</a>
    </p>
    <?php
    $wechat = get_the_author_meta('wechat');
    if ($wechat) {
        echo '<p>WeChat: ' . esc_html($wechat) . '</p>';
    }
    ?>
</div>

By flexibly using these functions and parameters, you can easily build author display modules that fit your site's design and functional needs.

Post a Comment

Your email will not be published. Required fields are marked with *.