Skip to content

dart-creations.com

Advertisement
Home arrow Joomla arrow Joomla Tips and Tricks arrow #3 - Hiding a menu once logged in
Print E-mail
Sunday, 03 June 2007

#3 - Hiding a menu once logged in

Have you ever wanted to hide one of your menus if your users have logged on? The following small template hack will hide your menu once your user has logged on.

 

The idea behind this is to actually load a particular position (the menu position) only if the user has not logged in:

Joomla 1.0 

if( !$my->id )mosLoadModules ( 'left' );

and should be placed in the index.php of the template you are using (/templates/<yourtemplate>/index.php). The code will hide all modules which are assigned to the left position. If you only want to hide your menu item, you should create an additional position in your template (e.g. hidingmenu), assign your hideable menu to this position and then hide that position only.

if( !$my->id )mosLoadModules ( 'hidingmenu' );

Joomla 1.5

This has changed for J1.5

$user =& JFactory::getUser();
$user_id = $user->get('id');

This returns the user id of the user.  Therefore the code to do this is check whether the current user has a valid id (i.e. they are logged), if not load the module:

<?php   
  $user =& JFactory::getUser();   
  $user_id = $user->get('id');   
  if (!$user_id)   
  {   
  ?>       
    <jdoc:include type="modules" name="left" />
  <?php
  }
?>
Comments
Search RSS
Marcio Martins  - Hide Modules   |93.102.4.xxx |2008-05-30 22:20:41
Hello.. I want to hide some modules when a registered user log in into the site.
In wich files I have to do this hack? I´m using joomla1.5

email:
desimarcio@gmail.com

very thanks
DART Creations  - Hide modules   |85.232.196.xxx |2008-05-31 07:22:17
Mancio,

best thing to do is to create a position in your template (check out
the tutorial on this site) and then hide it using the above technique when a
user logs in. You'll only have to hack your template.
Christian Sweningsen  - Confused re 1.0 & 1.5   |67.158.179.xxx |2008-06-11 15:32:47
Hi, Many thanks for very good tutorials, on good topics!

In this one, I'm not
clear which parts of the instructions go with J1.5; only the part with that
label; or (as it looks to me) also some of the 1.0?

thanks,
Christian
Chrille  - Great!     |83.209.62.xxx |2009-01-11 22:06:57
Just what I was looking for, thanks!
truongson.bkap   |58.187.149.xxx |2009-02-04 07:59:56
I want hidden list module manager. When login by supper administrator don't show
list module manager. I don't know hack code file ??? in folder???. please help
me.
Kroc   |198.143.195.xxx |2009-02-13 19:12:21
Great Post. I have one small issue, I used the right position as the one that
is only visible to guests. The menus in the right position are indeed hidden,
but the space is still being used as if the menu was there, just hidden. I am
running Joomla 1.5.

Thoughts? Thanks
DART  - Empty space   |Administrator |2009-02-14 07:51:08
The space is defined by the HTML elements of your template, you'll have to
insert the code in the appropriate places such that those elements
"collapse" when there are no menus being displayed.
Federico  - Voila, it works!     |213.156.52.xxx |2009-03-07 12:46:57
Great help in just a few lines of code!
Created a new position in my template,
added some lines to the it and its xml and everything worked just fine!
30
minutes and I got finally rid of the Login module once logged in.
Cool guides!
Keep up with them!
Veronika     |67.204.32.xxx |2009-06-11 16:37:56
Is it possible to use this code (altered)to show an additional menu to two
groups of users? Like Group A would see a menu A, Group B would see a menu B in
addition to all other menus?

Veronika
Only registered users can write comments!

3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."

Last Updated ( Wednesday, 01 October 2008 )
 

Sponsors

Friendly Links

VirtueMart Templates
SEO

Login Form






Lost Password?
No account yet? Register

Buy us a beer!

If we've helped you, consider buying a beer €3. It will inspire us to keep on giving! Cheers!


Generated in 0.30683 Seconds