Change login link to logout [Joomla]

. 7/26/10
  • Agregar a Technorati
  • Agregar a Del.icio.us
  • Agregar a DiggIt!
  • Agregar a Yahoo!
  • Agregar a Google
  • Agregar a Meneame
  • Agregar a Furl
  • Agregar a Reddit
  • Agregar a Magnolia
  • Agregar a Blinklist
  • Agregar a Blogmarks

How to change the 'login' menu item to 'logout' after the user has logged in?
I really struggled to find the solution for this. So here goes ...
Note: This solution is only for those users who want to use the Login link in the menu and connect it to the com_login in the main body of their joomla site
Summary:
  • We will try and achieve the desired result by creating two similar menus and two module positions corresponding to each menu.
  • The difference between the two will be that one has a Login link, the other has the Logout link.
  • We will then insert a piece of code in the template to toggle between the menus based on user login.
Steps:
  1. Go to Site, Template Manager, Module Positions
  2. Create 2 new module positions: pos_menuguest and pos_leftmenureg.
    (These will be used to switch between the login and logout button)
  3. Go to Menu, Menu Manager
  4. Create 2 Menu's: menuguest and menureg
  5. Go to Menu, menuguest
  6. Add the menu items you want shown when you are NOT logged in
  7. Make sure that your "Login" link is part of menuguest
  8. Go to Menu, menureg
  9. Add the content you want shown when you are logged in
  10. Make sure that the "Logout" link is part of menureg and Login IS NOT PART of menureg
  11. To ensure that there is no problem, change the Access Level of the Logout link to "Registered"
  12. Go to Modules, Site Modules, menuguest
  13. Assign it to position pos_menuguest
  14. Go to Modules, Site Modules, menureg
  15. Assign it to position pos_menureg
  16. Open your index.php of your template
    (or go to Site > Template Manager > Site Template > Edit HTML)
  17. Add the following in the appropriate place
    (usually within the "left_inner" div or the position in your template where you want the menu to appear)


    <?php
    if ($my->id) {
      mosLoadModules ('pos_menureg');
    }
    else {
      mosLoadModules('pos_menuguest');
    }
    ?>
If you have understood this procedure, you should be able to apply it to mod_login in a similar manner if required. This technique can be applied to other aspects of your site, like changing images, news items etc which depend on user login and cannot be controlled by joomla core.

0 comments: