How to get the name of the current page’s parent from the menu (i.e., get the title of the page one level up) in Joomla 1.5:
$menu = JSite::getMenu(); $parent = $menu->getItem($menu->getActive()->parent)->name;
$menu->getActive()->parent
returns the id of the parent, which is why you then have to pass that id to $menu->getItem([id])->name
. It would be nice to have a parent()
function so that you would only need $menu->getActive()->parent()->name
, but I quibble.
Photo: University of Washington Libraries Digital Collections, via Flickr Commons
Thanks. It is just what I was looking for.
Roman,
Glad you found it helpful.
Thanks so much… I forgot about this method!
Pingback: Joomla! | Warren Tang's Blog
Hi,
how to do this in Joomla 2.5?
Thanks.
Looks like in 2.5, the equivalent of:
$menu = JSite::getMenu();
is:
$menu = JFactory::getApplication()->getMenu();
Also, it looks like ->name has been replaced with ->title, at least in 3.0. Thanks for the info though 🙂
This is what works for me in 3.1:
$menu = JFactory::getApplication()->getMenu();
$parent = $menu->getItem($menu->getActive()->parent_id)->title;