• Resolved ktrusak

    (@ktrusak)


    I am looking to make a function for my banner that will display a message with the username if they are logged in, or a register link if they are not. I am totally new to this so help is appreciated, this is what I have started to piece together:

    <?php  if (is_user_logged_in()){
    global $current_user; get_currentuserinfo();
    echo('Welcome to Hookahi ' . $current_user->user_firstname . ' | ');
    }
    else {
    echo <?php printf(__(<a title=href="%s" rel="lightbox[registerform]">Register</a>, THEME_NS) , get_option('siteurl') . '/wp-login.php?redirect_to=' . urlencode(get_permalink())); ?>
    };
    ?>

    The lightbox plus thing is from a code I integrated in to the comment template so that the “you must be logged in thing” is a lightbox with a return redirect. I tried to just copy it here but its not working.. please help.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hmmm… some issues I can see with the above code…

    • In the echo statement you have opening and closing PHP tags, which you don’t need and could cause syntax errors.
    • There’s a echo printf, which will ultimately result in printing the string, but is a superfluous statement.
    • Not sure what’s going on at title=href=”%s”… my guess is that syntax isn’t accurate because it’s not valid HTML. I’d check the documentation for whatever lightbox implementation you’re using for the proper syntax.
    • There’s an extra semicolon after the closing brace for the else clause. It won’t generate an error, but it’s not necessary.

    Other than syntax issues, it looks like you’ve got the basic idea down… if logged in, get the user info (though if you’re doing this in a header template, I don’t know if this is needed… shouldn’t harm anything, though) and write out the first name, otherwise, show the signup link.

    Here’s my guess at what the code should probably look like:

    <?php
    if (is_user_logged_in()){
       global $current_user; get_currentuserinfo(); //might not need this line... try running the code without this
       echo('Welcome to Hookahi ' . $current_user->user_firstname . ' | ');
    } else {
       echo '__(<a href="'. get_option('siteurl') . '/wp-login.php?redirect_to=' . urlencode(get_permalink()).'" rel="lightbox[registerform]">Register</a>, THEME_NS);
    }
    ?>

    I hope this helps!

    Thread Starter ktrusak

    (@ktrusak)

    Thanks for the reply zimmi88! I put it in, but got a syntax error

    “Parse error: syntax error, unexpected T_STRING, expecting ‘,’ or ‘;’ “

    for this line:

    echo '__(<a href="'. get_option('siteurl') . '/wp-login.php?redirect_to=' . urlencode(get_permalink()).'" rel="lightbox[registerform]">Register</a>, THEME_NS);
    }
    ?>

    It’s that fist apostrophe after echo. Remove it.

    Thread Starter ktrusak

    (@ktrusak)

    Thanks, I put that in.

    Making progress.. now it says unexpected ‘<‘ expecting ‘)’

    echo __('<a href="'.

    Thread Starter ktrusak

    (@ktrusak)

    It works!

    Thanks zimmi88 and jevets for your help!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Welcome Statement or Log in Link’ is closed to new replies.