WordPress.org

Ready to get started?Download WordPress

Forums

post visible only when not logged (5 posts)

  1. jweaks
    Member
    Posted 8 years ago #

    How do I make a post ONLY visble to visitors who are NOT logged in? Basically, a welcome message that anyone logged in will not need to see.

    Thanks,
    jw

  2. zeroK
    Member
    Posted 8 years ago #

    Do you mean just a small or a whole post? In the first case, something like this should do it (inside of a template ;) ) :)

    <?php if (!$user_ID): ?>
    <p>Hello guest :-)</p>
    <?php endif; ?>

  3. Kafkaesqui

    Posted 8 years ago #

    If zeroK's suggestion doesn't work, make sure to scope $user_ID to global first:

    <?php global $user_ID; if (!$user_ID): ?>
    <p>Hello guest :-)</p>
    <?php endif; ?>

    See my plugin for a way to call a specific post:

    http://guff.szub.net/2005/01/27/get-a-post/

  4. jweaks
    Member
    Posted 8 years ago #

    Okay, I'm getting warm...

    I installed the get-a-post plugin and I added this code just above the Loop:

    <?php global $user_ID; if (!$user_ID): ?>
    <p>Hello guest :-)</p>
    <?php get_a_post('post#'); ?>
    <h3><?php the_title(); ?></h3>
    <?php the_content(); ?>
    <?php endif; ?>

    When I'm logged in, it does nothing... that is good.

    When I log out, I see the 'Hello Guest' text, so I know it's picking up that I'm not logged in, but...

    instead of the post I want to see it loads my contact form!?

    I tried different posts by number and by slug... with and without quotes... still nothing but the contact form.

    I have no idea why it would grab the Contact Form!?

    Definitely on the right track, but I must not be implementing the get-a-post properly.

    Thanks,
    jw

  5. jweaks
    Member
    Posted 8 years ago #

    aha!...

    I used this hack posted by "pati" at the get-a-post website:

    "...try putting parentheses around the last $query_suffix string, like this: $query_suffix = “(post_status = ‘publish’ OR post_status = ’static’)”;"

    That fixed it!

Topic Closed

This topic has been closed to new replies.

About this Topic