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

General questions relating to Joomla! 2.5. Note: All 1.6 and 1.7 releases have reached end of life and should be updated to 2.5. There are other boards for more specific help on Joomla! features and extensions.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
Locked
inderids
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Fri Apr 27, 2012 4:30 pm

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

Post by inderids » Sun May 20, 2012 12:58 am

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 ...

User avatar
imanickam
Joomla! Master
Joomla! Master
Posts: 28193
Joined: Wed Aug 13, 2008 2:57 am
Location: Chennai, India

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

Post by imanickam » Mon May 21, 2012 3:25 am

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.
Ilagnayeru (MIG) Manickam | இளஞாயிறு மாணிக்கம்
Joomla! - Global Moderators Team | Joomla! Core - Tamil (தமிழ்) Translation Team Coordinator
Former Joomla! Translations Coordination Team Lead
Eegan - Support the poor and underprivileged

inderids
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Fri Apr 27, 2012 4:30 pm

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

Post by inderids » Mon May 21, 2012 6:30 pm

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.

RedEye
Joomla! Ace
Joomla! Ace
Posts: 1460
Joined: Sat Jan 21, 2006 8:42 pm

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

Post by RedEye » Mon May 21, 2012 6:43 pm

$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.

inderids
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Fri Apr 27, 2012 4:30 pm

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

Post by inderids » Tue May 22, 2012 4:36 pm

wow wow wow .. :o

Thanks RedEye

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

Tons of Thanks

01peter
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 103
Joined: Thu Nov 05, 2009 6:49 pm

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

Post by 01peter » Tue Aug 21, 2012 8:50 am

hello guys.

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


Locked

Return to “General Questions/New to Joomla! 2.5”