Page 1 of 1

how to get the Title of Active Menu Item - Joomla 2.5

Posted: Sun May 20, 2012 12:58 am
by inderids
Hi
I am new to Joomla. I am using Joomla 2.5. I am trying to get the text of a Active menu item. I tried this code.
$menu = &JSite::getMenu();
$menuItem = $menu->getActive();
print_r("Active Menu ID ".$menuItem->id);

it gives me the id of active menu item. but i want to get the title or text of the active menu item.

Please help..
Thanks in advance ...

Re: how to get the Title of Active Menu Item - Joomla 2.5

Posted: Mon May 21, 2012 3:25 am
by imanickam
Suggest reviewing code of the extension Amplify title Module (http://extensions.joomla.org/extensions ... itles/6515). I believe that the function you looking for is in that module.

Re: how to get the Title of Active Menu Item - Joomla 2.5

Posted: Mon May 21, 2012 6:30 pm
by inderids
Dear imanickam
Tons of Thanks for replying.

Actually I figured out myself.
Here is the thing I was looking. I wanted to fetch the title of Active Menu Item. Following is the code to get the text of the Current Menu item clicked.

Code: Select all

/** Getting the Menu ID of Menu was clicked by user **/
$menu 	=	&JSite::getMenu(); 
$id 	=	$menu->getActive()->id;

/** Getting the Title of the Menu by using id. **/ 
$db 	= JFactory::getDBO();
$query 	= "SELECT title FROM kjs_menu WHERE id = $id";
$db->setQuery($query);
$rows 	= $db->loadObjectList();
$itemrow = $rows[0];
$title	=	$itemrow->title;

echo "Menu you have clicked is : ".$title;
I dnt know if there is other easy way to handle it. If anybody know please post it to me.

Re: how to get the Title of Active Menu Item - Joomla 2.5

Posted: Mon May 21, 2012 6:43 pm
by RedEye
$active = JFactory::getApplication()->getMenu()->getActive();
echo $active->title;

getActive gives back an object if it is able to get an active menu, so the object also include the title.
To make sure you have an object check it before you do any output.

Re: how to get the Title of Active Menu Item - Joomla 2.5

Posted: Tue May 22, 2012 4:36 pm
by inderids
wow wow wow .. :o

Thanks RedEye

it has reduced my code to just two line .. :D :D

Tons of Thanks

Re: how to get the Title of Active Menu Item - Joomla 2.5

Posted: Tue Aug 21, 2012 8:50 am
by 01peter
hello guys.

where do you put this code?? i would like to know that.