• Resolved Jeremy Sarber

    (@jsarber)


    I have this on an Authors archive page:

    <?php echo get_query_var('author_name'); ?>

    On the site, it displays the name with a hyphen like it does in the URL. For instance, Jeremy Sarber displays Jeremy-Sarber.

    What’s the problem?

Viewing 9 replies - 1 through 9 (of 9 total)
  • get_query_var() gets its values from the URL that was used to create the query. Check out the function get_the_author().

    Thread Starter Jeremy Sarber

    (@jsarber)

    Thanks for the reply. Unfortunately, that leaves the name missing.

    This:
    Shows hosted by <?php $author = get_the_author(); ?>:

    Becomes this:

    Show hosted by :

    Moderator Kathryn Presner

    (@zoonini)

    I’m not sure if this is the issue, but maybe worth a try: put back your original line of code, go into Users > and select a user. For each user there should be a drop-down menu where you can select how you want the name to be displayed on the public side – there should be a few options. Let me know if this helps.

    Thread Starter Jeremy Sarber

    (@jsarber)

    I appreciate you trying but it didn’t change anything. I believe vtxyzzy was right. It’s pulling the name from the URL (domain.com/author/USER-NAME/).

    But every other string of script I’ve tried causes the name to go missing altogether.

    Moderator Kathryn Presner

    (@zoonini)

    No worries. I should have checked some actual code first. 😉

    This is what I use to display the author’s name:

    <?php the_author(); ?>

    …in conjunction with selecting from each user’s drop-down the desired name format. Let me know if it works.

    Thread Starter Jeremy Sarber

    (@jsarber)

    I just figured it out.

    I can use this:
    <?php echo $curauth->nickname; ?>

    So long as I changed some above script to this:

    <?php
    $curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));
    ?>

    Thanks for your help.

    Moderator Kathryn Presner

    (@zoonini)

    Glad you found a solution. If you would please mark this thread as “resolved” it would be appreciated. Helps everyone keep better track of whose issues are still outstanding. Thanks!

    OK, the_author() is only good when processing posts in the Loop. It gets the author of the current post. If you are not viewing posts, you have to use a different approach. See the Codex on Custom Author Information for some alternatives.

    EDIT: OOPS – you beat me to it.

    Moderator Kathryn Presner

    (@zoonini)

    Thanks for the clarification vtxyzzy – I goofed and forgot we were talking about the author’s archive page.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Problem with displaying author_name’ is closed to new replies.