WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Author's name on archive page (9 posts)

  1. steve2010
    Member
    Posted 3 years ago #

    Is there a way to change the header of the "author archive" page without creating an author archive template, perhaps just by modifying the archives template php? I'd like to add the author's name since this is a multi-author site.

  2. forunner
    Member
    Posted 3 years ago #

  3. Mark / t31os
    Moderator
    Posted 3 years ago #

    Yes the codex is great i agree, but unfortunately it does not answer the question being asked.

    Steve, you'll need to work out which file currently displays the unwanted heading and add an additional conditional statement..

    For example let's say you have a few lines like this (example only, obviously yours will differ)..

    <?php if( is_archive() ) : ?>
       <!-- archive heading HTML -->
    <?php elseif( is_category() ) : ?>
       <!-- category heading HTML  -->
    
    ... and so on..

    You'd then just add another condition like so..

    <?php if( is_archive() ) : ?>
       <!-- archive heading HTML -->
    <?php elseif( is_category() ) : ?>
       <!-- category heading HTML -->
    <?php elseif( is_author() ) : ?>
       <!-- your new author heading HTML here  -->
    
    ...etc..

    If that's a little too much for you to follow, post the code from the file that currently deals with the heading and i'll help you do it... ;)

    If posting code, please use a pastebin... :)
    http://wordpress.pastebin.com/

  4. steve2010
    Member
    Posted 3 years ago #

    Hi Mark,

    Thanks for the reply.

    The code is at http://wordpress.pastebin.com/p4ed6CjN

    (or should I send it to you in another format?)

    What I'd like to do is change the header on the author archive page. Now it reads "Author Archive." I'd like it to read something like "Archive for [author's name]". Thanks for the help.

  5. Mark / t31os
    Moderator
    Posted 3 years ago #

    Is the author name shown in the URL when displaying an author page on your site?

    If so, try updating this line..

    <h2 class="pagetitle">Author Archive</h2>

    For.

    <h2 class="pagetitle">Archive for <?php echo get_query_var('author_name'); ?></h2>

    If not, i'll have to come up with something else for you.. :)

  6. steve2010
    Member
    Posted 3 years ago #

    No, unfortunately, the URL for the author archive page just ends with the number ID for the user, e.g., /?author=2. (I could try getting the author name into the URL using permalink, but I'm not sure how to structure the permalink so it works the way you've set this up.) Thanks for following up on this.

  7. Mark / t31os
    Moderator
    Posted 3 years ago #

    Ok, switch that for..

    <?php
    if(get_query_var('author_name')) :
        $curauth = get_user_by('slug', get_query_var('author_name'));
    else :
        $curauth = get_userdata(get_query_var('author'));
    endif;
    ?>
    <h2 class="pagetitle">Archive for <?php echo $curauth->nickname; ?></h2>

    Will support both author name and author id queries.

    As seen in the example on the author template codex page.
    http://codex.wordpress.org/Author_Templates

    Hope that helps.. ;)

  8. steve2010
    Member
    Posted 3 years ago #

    Mark,

    That worked perfectly. Very impressive. Thanks a bunch, really.

    Steve

  9. Mark / t31os
    Moderator
    Posted 3 years ago #

    You're welcome.. :)

Topic Closed

This topic has been closed to new replies.

About this Topic