Front-end Web Developer | Tampa, FL

How to create link to login page in Joomla?

Posted on: May 18th, 2010 by admin No Comments

 

If we want to add a bit of user interactivity then we first need to get the users name with a JFactory call and store it in a variable which we place in the php section of the template:

 

{CODE type:php;}

$username =& JFactory::getUser();

{/CODE}

 

Then we can use this to show Register, Login links or Logout link, it depends of user logged in or not.

 

{CODE type:php;}

<div id=”loginArea”>
<?php
 if ($username->guest) {
 echo ‘<a href=”http://www.YourSiteName.com/index.php?option=com_user&view=register” title=”Register”>Refister</a> ‘;
 echo ‘<a href=”http://www.YourSiteName.com/index.php?option=com_user&view=login” title=”Login”>Login</a>’;
   } else {
   $name = $username->get(‘username’);
   echo ‘Hi ‘ . $name . ‘ –  <a href=”http://www.YourSiteNome.com/index.php?option=com_user&view=logout” title=”Logout”>Logout</a>’;
   }
 ?>
</div><!– End Login Area –>

{/CODE}

 

I hope it will be useful for you 🙂

Comments are closed.