WordPress.org

Ready to get started?Download WordPress

Forums

Adding a user welcome to template header (12 posts)

  1. mattaudio
    Member
    Posted 8 years ago #

    Notice how at the top of this forum, if you are logged in, you see

    "Welcome, USER! View your profile » (Logout)"
    -- that's exactly what I want to put in my WordPress template, but I can't figure out the right tags to do it. Any ideas?

  2. pizdin_dim
    Member
    Posted 8 years ago #

    Try putting this into your (template) sidebar or header:


    <?php if ($user_level > 0): ?>
    Welcome, <?php echo $user_nickname; ?>! <a href="<?php bloginfo('wpurl'); ?>/wp-admin/profile.php" title="View your profile">View your profile</a> » (<a href="<?php bloginfo('wpurl'); ?>/wp-login.php?action=logout" title="Logout">Logout</a>)
    <?php endif; ?>

  3. mattaudio
    Member
    Posted 8 years ago #

    I pasted that code in my header and for some reason nothing shows up, not even in the source, as long as its inside that if. I don't know PHP very well, so I don't know what would keep it from working.

  4. pizdin_dim
    Member
    Posted 8 years ago #

    It should never show up in the source, unless your webserver is broken. Have you pasted the code into your current template? Which one? Which file? Where did you put it?

  5. mattaudio
    Member
    Posted 8 years ago #

    Here is the page. It should be at the top, right above the logo.

    Here's my non-theme test page that I'm trying to imitate... check it out to see what I had. Everything is contained within a p tag with class "topline".

    Thanks so much for helping me!

  6. pizdin_dim
    Member
    Posted 8 years ago #

    I'm not familiar with the template you're using but if it's one of the many WP templates out there, I assume you have put the code here:

    /wprecord/static/wp-content/themes/dw_template/header.php

    Looking at your HTML source, it's likely to be after the <div id="header"> and between the <p> and </p> tags. Is that right? If so, you should probably have the code enclosed in a <div> instead of a <p> tag.

    I don't see the topline class in your source code, which leads me to believe that perhaps you didn't put the code in the right file.

  7. mattaudio
    Member
    Posted 8 years ago #

    Hey I couldn't look at this yesterday. It's right after <div id="header"> inside header.php. I changed it so all that code above is inside another <div> instead of a <p>.

    It still doesn't seem to work. The odd thing is it looks fine if I just put in regular text w/o the PHP. Any ideas?

    BTW, it is a template I'm making for this newspaper that's still in progress. Thanks!

  8. Kafkaesqui

    Posted 8 years ago #

    Try changing the initial line of pizdin's code to:

    <?php global $user_identity; if ($user_identity): ?>

  9. mattaudio
    Member
    Posted 8 years ago #

    Okay now it shows up when I'm logged in. The only problem is that it calls the user nickname to display. I can't seem to find these user_ tags in the codex. (I'm looking here) Is there a place that lists these tags?

    Also: Is it easy to say if nobody is logged in, display something like Welcome | Register? Thanks so much!

  10. Kafkaesqui

    Posted 8 years ago #

    The $user_* are global variables, not tags. They are made global under many conditions in WordPress, especially after one runs the get_currentuserinfo() function. The variables that are scoped globally by it are generally:

    $user_login - login name pulled from cookie.
    $userdata - PHP oject includes all user profile data
    $user_level
    $user_ID
    $user_email
    $user_url
    $user_pass_md5 = password encrypted in md5 hash;
    $user_identity = user's selected display name;

    To change from the user nickname to something else (say their display name), look for:

    <?php echo $user_nickname; ?>

    and change it to:

    <?php echo $user_identity; ?>

    But whatever you choose, make sure to scope it to global first, as we do above to $user_identity.

  11. Kafkaesqui

    Posted 8 years ago #

    RE: Also...

    Change:

    <?php endif; ?>

    to something like:

    <?php else : ?>
    <?php wp_register(); ?>
    <?php endif; ?>

    More on wp_register() template tag:

    http://codex.wordpress.org/Template_Tags/wp_register

  12. mattaudio
    Member
    Posted 8 years ago #

    Sweet! Thanks! Check it out: http://www.users.csbsju.edu/wprecord/

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags