WordPress.org

Ready to get started?Download WordPress

Forums

Starting the Loop in header.php (5 posts)

  1. hami
    Member
    Posted 8 years ago #

    I'm hoping someone can help me here. I want to put the the_author_login in the header of my site. I just can't work out how to start the loop in there. This is the code i'm using:


    <?php if (is_home()) : ?>
    Welcome: <?php the_author_login(); ?>
    <?php endif; ?>

    I'm sure the if clause is bad, but I couldn't think of anything else to use. It shows the 'Welcome:' bit but not the_author_login - so I guess the loop isn't working.

    Any ideas what I've done wrong?

    thanks in advance

    Hami

  2. lynk
    Member
    Posted 8 years ago #

    Try this:

    Welcome:
    <?php
    if (have_posts()){
    the_post();
    the_author_login();
    }
    ?>

  3. TechGnome
    Moderator
    Posted 8 years ago #

    From the codex: Displays the login name for the author of a post.

    So..... how can it be in the header? It's going to need to go with the posts that the author wrote....

    -tg`

  4. hami
    Member
    Posted 8 years ago #

    Thanks Lynx,

    That code breaks the posts and replaces it with 'No Posts Found', but does put what I wanted in the header.

    But TechGnome is right I shouldn't be using the_author_login, it's the wrong tag. What I want to do is put the current logged in user's name in the header - Welcome: Username

    Do you know if this can be done?

    thanks

    Hami

  5. lynk
    Member
    Posted 8 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic