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

Postby 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: 24580
Joined: Wed Aug 13, 2008 2:57 am
Location: Chennai, India

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

Postby imanickam » Mon May 21, 2012 3:25 am

Suggest reviewing code of the extension Amplify title Module (http://extensions.joomla.org/extensions/style-a-design/titles/6515). I believe that the function you looking for is in that module.
- Ilagnayeru (MIG) Manickam
http://www.eegan.org - helping the poor and underprivileged
educate. empower. enrich.
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

Postby 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: 1441
Joined: Sat Jan 21, 2006 8:42 pm

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

Postby 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

Postby 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

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

hello guys.

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


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

Who is online

Users browsing this forum: No registered users and 14 guests