简体   繁体   English

Joomla 2.5 添加父别名作为正文 class

[英]Joomla 2.5 add parent alias as body class

The code changed since Joomla 1.5, here's my try:代码自 Joomla 1.5 以来发生了变化,这是我的尝试:

In the head在头

<?php $parent = JFactory::getApplication()->getMenu()->getParent(); ?>  

On the body tag在身体标签上

<body class="<?php echo $parent->alias; ?>">

Any idea of what's wrong...?知道出了什么问题......? Thanks谢谢

Found your post then found this, which I think answers it perfectly, well at least it did for me找到你的帖子然后找到这个,我认为这完美地回答了它,至少它对我有用

http://www.joomla4web.com/blog/finding-the-top-menu.html http://www.joomla4web.com/blog/finding-the-top-menu.html

 $menu = JFactory::getApplication()->getMenu();
$active = $menu->getActive();
$top = $active ? $menu->getItem($active->tree[0]) : null;
echo $top->alias;

I am using:我在用:

<?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 . '"'; ?>>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM