• hi i’m looking for a way to show guest a welcome post that tells them to log in, and the moment the are logged in that post should hide because now when there logged in that post still shows

Viewing 8 replies - 1 through 8 (of 8 total)
  • It’s probably easier to do this with static text rather than a post. First detect if the user is logged in. If he isn’t, then display the text.

    Something like this (untested):

    <?php if ( !$user_ID ) { //If not logged in. ?>
    	<p>Please <a href="<?php echo get_option('siteurl'); ?>/wp-login.php">log in</a>.</p>
    <?php } ?>
    Thread Starter kwantakosta

    (@kwantakosta)

    yeah but i don’t want them to get to the ugly login from wordpress, i have a login widget, and changed the logout to go to index.php, the users should never have to see the wordpres behind the site

    Quick and dirty fix inside the loop, lets say the welcome message is post id 12

    <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
    <?php if ($post->ID==12 && is_user_logged_in() ) return; ?>

    Not a lover of hard coded values, so a bit more tidy make the welcome post a sticky and code inside the loop:

    <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
    <?php if ( is_sticky() && is_user_logged_in() ) return; ?>

    Thanks for this idea, I am going to use it on my own supporters site.

    HTH

    David

    Thread Starter kwantakosta

    (@kwantakosta)

    ok thx and where should i put this ? in index.php ?

    That would depend on your theme, but yes the index.php or the loop.php the key is to look inside the loop, for the ‘while’ statement!

    David

    [adaptris beat me :-0 )

    Thread Starter kwantakosta

    (@kwantakosta)

    ok thanks but it’s not able to do that like with “widget logic”, whit that i can add the “is_user_logged_in” key to any widget, i was hoping there was a plugin for a post like that to ?

    Not that I know of, I have just implemented it on my supporters subsite, but had to change the logic slightly, I am using the p2 theme and thw welcome post is a sticky.

    <?php if ( have_posts() ) : ?>
    
    	<?php while ( have_posts() ) : the_post(); ?>
    
    		<?php if (!( is_user_logged_in() && is_sticky() ) ) p2_load_entry(); // loads entry.php ?>
    
    	<?php endwhile; ?>
    
    <?php else : ?>
    
    	<li class="no-posts">
        	<h3><?php _e( 'No posts yet!', 'p2' ); ?></h3>
    	</li>
    
    <?php endif; ?>

    HTH

    David

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to hide a post when logged in’ is closed to new replies.