How to get active menu item properties in joomla

May 17, 2010 by satz  
Filed under CMS, Joomla

This tutorial explains about how to get the active menu item properties in joomla. This method is very much useful for those who want to have some conditional statements to be executed in the template depends on the current menu item property values.

The following syntax gets the current menu name:

$currentMenuName = JSite::getMenu()->getActive()->name ;

The following syntax gets the current menu Id:

$currentMenuId = JSite::getMenu()->getActive()->id ;

The following syntax gets the current menu status, published values (It will be 1 if published):

$currentMenuStatus = JSite::getMenu()->getActive()->published ;

The following syntax gets the non-Seo friendly URL of the current menu :

$currentMenuLink = JSite::getMenu()->getActive()->link ;

The following syntax gets the current Menu’s parent Menu item ID (For top level and the home page the value will be 0):

$currentMenuParent = JSite::getMenu()->getActive()->parent ;

The following syntax gets the current Menu’s Access Level Value.(Public = 0, Registered = 1, Special= 2)

$currentMenuAccess = JSite::getMenu()->getActive()->access ;

  • Leave a Comment

    Leave your sincere comments and feed backs below. It helps us to improve the quality and encourages us to do more.

Comments

2 Responses to “How to get active menu item properties in joomla”
  1. M.G. says:

    The lines works for me only in following structure:
    $menu = &JSite::getMenu();
    $active = $menu->getActive();
    echo $active->name;
    echo $active->id;
    echo $active->published;

    ….

    Greetings
    M.G.

  2. satz says:

    Hello M.G.

    Thanks for the information.

    Warm Regards,
    Satz

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!