Basic PHP markup for the author.php template, WordPress

The author.php template in WordPress is used to display author archive pages, where their posts and additional information are shown. Here’s a basic structure for the author.php file:

<?php
/**
 * The template for displaying Author archive pages
 *
 * @package YourThemeName
 */

get_header(); ?>

<div class="author-page">
    <header class="author-header">
        <?php
        // Get author data
        $author = get_queried_object();
        ?>
        <h1 class="author-title"><?php echo esc_html($author->display_name); ?></h1>

        <?php if (get_the_author_meta('description', $author->ID)) : ?>
            <p class="author-bio"><?php echo esc_html(get_the_author_meta('description', $author->ID)); ?></p>
        <?php endif; ?>
    </header>

    <div class="author-posts">
        <?php if (have_posts()) : ?>
            <h2><?php esc_html_e('Posts by ', 'your-text-domain'); ?><?php echo esc_html($author->display_name); ?>:</h2>
            <ul class="author-post-list">
                <?php while (have_posts()) : the_post(); ?>
                    <li>
                        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                        <span class="post-date"><?php echo get_the_date(); ?></span>
                    </li>
                <?php endwhile; ?>
            </ul>
        <?php else : ?>
            <p><?php esc_html_e('This author has no posts yet.', 'your-text-domain'); ?></p>
        <?php endif; ?>
    </div>
</div>

<?php get_footer(); ?>

Key Points:

  1. Author Header:
    • The author’s name is displayed using get_queried_object().
    • The author’s description is fetched using get_the_author_meta('description').
  2. Author Posts:
    • The standard WordPress Loop is used to display the author’s posts.
    • If the author has no posts, a fallback message is shown.
  3. Translation:
    • Use WordPress translation functions like esc_html_e() and esc_html__().
  4. Security:
    • Data is output with proper escaping functions such as esc_html().

Additional Notes:

  • Add relevant CSS classes for styling the template.
  • If you need extended functionality, such as adding custom fields, you can use get_user_meta()

How useful is the publication?

Click on a star to rate it!

Average score 5 / 5. Number of grades: 1

No ratings yet. Rate it first.

Similar posts

How to transfer a site from dle to WordPress?

Transferring a website from DLE (DataLife Engine) to WordPress can be a complex process, especially if the site has a lot of content. Here’s a step-by-step guide: 1. Preparation 2. Export Data from DLE DLE uses its own database structure, so you’ll need to export data and convert it into a format compatible with WordPress:…
Read more