• My site (MediaHug.com) has a small message bar at the top that reminds readers to register. I’d like to know how I can control it so that only guests can view the bar.

    ?? Help much appreciated.

Viewing 6 replies - 1 through 6 (of 6 total)
  • I have something like this in one of the blogs:

    <?php
    global $user_login, $user_identity;
    get_currentuserinfo();
    if ($user_login) :
    ?>
    <div class="whatever">
    <strong>Hello <?php echo $user_identity; ?>!<br />
    </div>
    <?php else : ?>
    <div class="mydiv">
    <b>Welcome! Hey, Login ... +your text </b>
    </div>
    <?php endif; ?>

    Thread Starter xitanto

    (@xitanto)

    Moshu – thanks. ??

    I’ve put it in to the code, and it does work well.

    <?php
    global $user_login, $user_identity;
    get_currentuserinfo();
    if ($user_login) :
    ?>
    <?php else : ?>
    <?php easy_announcement(); ?>
    <?php endif; ?>

    Any way to trim it down a bit? I don’t need to find the user’s login name, I just need to block them from seeing <?php easy_announcement(); ?> when they’re logged in.

    In other words, is it possible to cut the code down a fraction?

    The only thing you can take out (though I am not a coder!!! – you were warned:) – might be the user_identity.

    Thread Starter xitanto

    (@xitanto)

    hmm… Might wait till a coder can give me an answer on that one. ?? But thanks. ^_^

    Well you could just … try to cut out things and see what happens ??

    <?php global $user_login;
    get_currentuserinfo();
    if (!$user_login) easy_announcement(); ?>

    This topic is very useful when running PHP (using PHP-exec or another one) in a post, just to inform the visitors wether they are currently logged in or not, when you use the HIDETHIS plugin or a post restriction plugin.
    Example:

    <font color="red" size="1" face="arial"><phpcode>
    <?php global $user_login, $user_identity;
    get_currentuserinfo();
    if ($user_login) :
    ?>
    You are OK!
    <?php else : ?>
    You are off!
    <?php endif; ?>
    </phpcode></font>

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Hide a <div> when user is logged in.’ is closed to new replies.