Forums

Trying to get a conditional login box/ welcome text at top of page? Help?! (4 posts)

  1. tommyteetz
    Member
    Posted 4 months ago #

    Hey Guys, Thanks in advance for any help.

    I am using a highly customised version of Twenty Eleven and basically I am trying to add a section into my header.php to appear at the top of all pages. It is to be two things.

    1) If you are logged in, display the text "Welcome, USER NAME"
    2) If you are logged out, display the text "Login Now >" which will then link to a lightbox or hover of somesort with the login box itself.

    I am proficient with HTML/ CSS and a novice but like to experiment with PHP and I thought I had it sussed but it keeps spitting out errors, with the code below I get an error. (Code below, then error follows).

    <div id="login">
    
    			<!-- Content to be shown if logged in -->
    			<?php if ( is_user_logged_in() ) ?>
    
    				<!-- Display Username / if logged in -->
    				<p class="logn-text-top">Welcome, <?php echo $current_user->user_login; ?></p>
    
    			<!-- Content to be shown if not logged in -->
    			<?php } else { ?>
    
    				<a href="#"><p class="login-text-top">Login Now<span>></span></p></a>
    
    			<?php } ?>
    
    			</div>

    The Error I get is:

    Parse error: syntax error, unexpected '}' in /web_local/docroot/1310/cheshirefitcamps.co.uk/htdocs/wp-content/themes/cheshirefitcamps/header.php on line 107

    I've checked the code over and searched the net but as far as I can see the code is fine.

    Any help would be appreciated.

    Kind Regards,
    Tom

  2. alchymyth
    The Sweeper
    Posted 4 months ago #

  3. tommyteetz
    Member
    Posted 4 months ago #

    Thanks, but this doesn't really help. I've cross checked my code with that page and one of the examples on there:

    <?php if($variable == 'S') {?>
    <input name="blah" type="radio" value="Y" checked="checked"> Yes
    <input name="blah" type="radio" value="N"> No
    <?php } else {?>
    <input name="blah" type="radio" value="Y"> Yes
    <input name="blah" type="radio" value="N" checked="checked"> No
    <?php }?>

    Matches up to the format of mine, so I still DON'T know why it isn't working.

    Many Thanks

  4. tommyteetz
    Member
    Posted 4 months ago #

    Figured it out! it was missing a bracket is all.

Reply

You must log in to post.

About this Topic