set display by role programmatically in Drupal 7

I want to display this text link, <p><a href ="register">Click here to register.</a></p> in the body of a larger block of text on a page and but I want the link to show up when some is logged in. I want to use php conditional to show this other link when someone is instead anonymous on the site,

<p>You need to login before you can register. Please <a href="login">Click here to login.</a>

I want a code like:

if user=="logged-in";
    echo "<a href ='register'>Click here to register.</a>";
    else echo "<a href ='login'>Click here to login.</a>"

I know I must not have written perfect php but I do not have problems with the php, what I need is the Drupal syntax for if user == "logged-in" and if user == "not-logged-in".

I do not want to use a block and start setting visibility by role. I want to use code as described.


Source: syntax

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.