get body class by active parent menu item
example:
menuitem 1
menuitem 1.1 menuitem 1.2 menuitem 1.2.1 menuitem 2 menuitem 3I now have:
<?php $active = JFactory::getApplication()->getMenu()->getActive();?>
<body class="<?php echo $active->alias; ?> ">
So I load the body class from the active menu item. I'd like that to stay the same. The thing I need is to hide certain menu item's when for example menuitem 1 is active. So when that happens I need to assign a class to menuitem 2.开发者_如何学C
That way when I navigate down 1.1 it keeps the menu items hidden.
Found a solution:
<?php
$menu =& JSite::getMenu();
$active = $menu->getActive();
$class = extractpath($active->route);
function extractpath($string){
preg_match('/^[a-zA-Z0-9\-_]+/',$string,$m);
return $m[0];
}
?>
<body<?php if ($class) echo ' class="' . $class . '"'; ?>>
To get the ID of the parent - $menu->getActive()->parent
To get the Title of the parent - $menu->getItem([id])->name
精彩评论