突出显示Joomla中的活动菜单项
我正在覆盖Joomla 1.5中的mod_mainmenu模块,无法获取要在页面上显示的突出显示Joomla中的活动菜单项,joomla,Joomla,我正在覆盖Joomla 1.5中的mod_mainmenu模块,无法获取要在页面上显示的.active或#currentCSS类或ID。它将为菜单显示以下HTML: <ul id="top-nav" class="flatList"> <li access="0" level="1" id="1"> <a href="#"> <span class="embed embed-top-nav">Home</span>
.active
或#current
CSS类或ID。它将为菜单显示以下HTML:
<ul id="top-nav" class="flatList">
<li access="0" level="1" id="1">
<a href="#">
<span class="embed embed-top-nav">Home</span>
<p>news, highlights</p>
</a>
</li>
<li access="0" level="1" id="4">
<a href="/content/index.php?option=com_content&view=article&id=1&Itemid=4">
<span class="embed embed-top-nav">Watch UNC-TV</span>
<p>schedule, programs</p>
</a>
</li>
</ul>
检查你的模板文件夹,有一个template.css文件,你可以在那里找到 试试这个,下面是mod_主菜单(覆盖)的代码:
getActive();
$path=isset($active)?array\u reverse($active->tree):空;如果($args['end'])&($node->attributes('level')>=$args['end']))
{
$children=$node->children();
foreach($node->children()作为$child)
{
如果($child->name()=='ul'){
$node->removeChild($child);
}
}
}
如果($node->name()=='ul'){
foreach($node->children()作为$child)
{
如果($child->attributes('access')>$user->get('aid',0)){
$node->removeChild($child);
}
}
}
if(($node->name()='li')&&isset($node->ul)){
$node->addAttribute('class','parent');
}
if(isset($path)和&in_数组($node->attributes('id'),$path))
{
如果($node->attributes('class')){
$node->addAttribute('class',$node->attributes('class').'active');
}否则{
$node->addAttribute('class','active');
}
}
其他的
{
如果(isset($args['children'])和&!$args['children']))
{
$children=$node->children();
foreach($node->children()作为$child)
{
如果($child->name()=='ul'){
$node->removeChild($child);
}
}
}
}
如果(($node->name()='li')&($id=$node->attributes('id')){
如果($node->attributes('class')){
$node->addAttribute('class',$node->attributes('class')。'item'.$id);
}否则{
$node->addAttribute('class','item'.$id);
}
}
if(isset($path)&&&$node->attributes('id')==$path[0]){
$node->addAttribute('id','current');
}否则{
$node->removeAttribute('id');
}
$node->removeAttribute('level');
$node->removeAttribute('access');
}
定义('modMyMainMenuXMLCallbackDefined',true);
}
ob_start();
modMainMenuHelper::render($params,'modMyMainMenuXMLCallback');
$menu_html=ob_get_contents();
ob_end_clean();
如果($params->get('menutype')==“mainmenu”){
$tag=$params->get('tag_id');
}
//输出菜单!
echo fancyMenuPatch($menu\u html,$tag);
?>
您可以将代码发布到覆盖文件中吗?活动菜单ID和类在核心模板文件中设置,如果要覆盖它,则需要对此进行说明。谢谢,Brent。我明天会把代码发出去;现在无法访问它。菜单结构似乎不是由mod_mainmenu生成的。再次检查,这可能是由其他菜单模块生成的。@Prakash,谢谢您的回复。它使用mod_主菜单,因为我使用覆盖生成输出。但是,我不确定为什么没有设置活动
/当前
属性。最后的结果不应该有访问
和级别
属性。我在这里使用的示例是:在那里的代码底部,它检查菜单类型
是否等于主导航
,以设置$tag
。在我的例子中,我发现我没有使用那个菜单类型,而是使用main菜单
。这可能是问题的根源吗?什么是primarynav
?在Google上找不到任何内容。我使用的自定义模板没有template.css文件。谢谢,Prakash。这管用!但是为什么呢?我的mod_主菜单覆盖有什么问题?不要!!我看到了我的错误:我将mod函数拼写为modMainMenuXMLCallback
,然后通过调用modMyMainMenuXMLCallback
来呈现它。该死。
<?php
// no direct access
defined('_JEXEC') or die('Restricted access');
if ( ! defined('fancyMenuPatch') )
{
function fancyMenuPatch($result,$tag){
$menu = JSite::getMenu();
$active = $menu->getActive();
// Add to the start of the UL tag.
$begin_ul = "<ul id=\"top-nav\" class=\"flatList\">";
$begin_span = "<span class=\"embed embed-top-nav\">";
$home_p = "Home</span><p>news, highlights</p></a>";
$watch_p = "Watch UNC-TV</span><p>schedule, programs</p></a>";
$learn_p = "Learn</span><p>education, unc-tv kids</p></a>";
$support_p = "Support Us</span><p>pledge, volunteer, corporate</p></a>";
$contact_p = "Contact</span><p>feedback, connect, share</p></a>";
// do the replacements
$result = str_replace("<ul class=\"menu\">",$begin_ul, $result);
$result = str_replace("<span>", $begin_span, $result);
$result = str_replace("Home</span></a>",$home_p,$result);
$result = str_replace("Watch UNC-TV</span></a>",$watch_p,$result);
$result = str_replace("Learn</span></a>",$learn_p,$result);
$result = str_replace("Support Us</span></a>",$support_p,$result);
$result = str_replace("Contact</span></a>",$contact_p,$result);
return $result;
}
define('fancyMenuPatch', true);
}
if ( ! defined('modMainMenuXMLCallbackDefined') )
{
function modMainMenuXMLCallback(&$node, $args)
{
$user = &JFactory::getUser();
$menu = &JSite::getMenu();
$active = $menu->getActive();
$path = isset($active) ? array_reverse($active->tree) : null;
if (($args['end']) && ($node->attributes('level') >= $args['end']))
{
$children = $node->children();
foreach ($node->children() as $child)
{
if ($child->name() == 'ul') {
$node->removeChild($child);
}
}
}
if ($node->name() == 'ul') {
foreach ($node->children() as $child)
{
if ($child->attributes('access') > $user->get('aid', 0)) {
$node->removeChild($child);
}
}
}
if (($node->name() == 'li') && isset($node->ul)) {
$node->addAttribute('class', 'parent');
}
if (isset($path) && (in_array($node->attributes('id'), $path) || in_array($node->attributes('rel'), $path)))
{
if ($node->attributes('class')) {
$node->addAttribute('class', $node->attributes('class').' active');
} else {
$node->addAttribute('class', 'active');
}
}
else
{
if (isset($args['children']) && !$args['children'])
{
$children = $node->children();
foreach ($node->children() as $child)
{
if ($child->name() == 'ul') {
$node->removeChild($child);
}
}
}
}
if (($node->name() == 'li') && ($id = $node->attributes('id'))) {
if ($node->attributes('class')) {
$node->addAttribute('class', $node->attributes('class').' item'.$id);
} else {
$node->addAttribute('class', 'item'.$id);
}
}
if (isset($path) && $node->attributes('id') == $path[0]) {
$node->addAttribute('id', 'current');
} else {
$node->removeAttribute('id');
}
$node->removeAttribute('rel');
$node->removeAttribute('level');
$node->removeAttribute('access');
}
define('modMainMenuXMLCallbackDefined', true);
}
ob_start();
modMainMenuHelper::render($params, 'modMyMainMenuXMLCallback');
$menu_html = ob_get_contents();
ob_end_clean();
if($params->get('menutype')=="mainmenu"){
$tag = $params->get('tag_id');
}
//output the menu!
echo fancyMenuPatch($menu_html,$tag);
?>
<?php
// no direct access
defined('_JEXEC') or die('Restricted access');
if ( ! defined('fancyMenuPatch') )
{
function fancyMenuPatch($result,$tag){
$menu = JSite::getMenu();
$active = $menu->getActive();
// Add to the start of the UL tag.
$begin_ul = "<ul id=\"top-nav\" class=\"flatList\">";
$begin_span = "<span class=\"embed embed-top-nav\">";
$home_p = "Home</span><p>news, highlights</p></a>";
$watch_p = "Watch UNC-TV</span><p>schedule, programs</p></a>";
$learn_p = "Learn</span><p>education, unc-tv kids</p></a>";
$support_p = "Support Us</span><p>pledge, volunteer, corporate</p></a>";
$contact_p = "Contact</span><p>feedback, connect, share</p></a>";
// do the replacements
$result = str_replace("<ul class=\"menu\">",$begin_ul, $result);
$result = str_replace("<span>", $begin_span, $result);
$result = str_replace("Home</span></a>",$home_p,$result);
$result = str_replace("Watch UNC-TV</span></a>",$watch_p,$result);
$result = str_replace("Learn</span></a>",$learn_p,$result);
$result = str_replace("Support Us</span></a>",$support_p,$result);
$result = str_replace("Contact</span></a>",$contact_p,$result);
return $result;
}
define('fancyMenuPatch', true);
}
if ( ! defined('modMyMainMenuXMLCallbackDefined') )
{
function modMyMainMenuXMLCallback(&$node, $args)
{
$user = &JFactory::getUser();
$menu = &JSite::getMenu();
$active = $menu->getActive();
$path = isset($active) ? array_reverse($active->tree) : null; if (($args['end']) && ($node->attributes('level') >= $args['end']))
{
$children = $node->children();
foreach ($node->children() as $child)
{
if ($child->name() == 'ul') {
$node->removeChild($child);
}
}
}
if ($node->name() == 'ul') {
foreach ($node->children() as $child)
{
if ($child->attributes('access') > $user->get('aid', 0)) {
$node->removeChild($child);
}
}
}
if (($node->name() == 'li') && isset($node->ul)) {
$node->addAttribute('class', 'parent');
}
if (isset($path) && in_array($node->attributes('id'), $path))
{
if ($node->attributes('class')) {
$node->addAttribute('class', $node->attributes('class').' active');
} else {
$node->addAttribute('class', 'active');
}
}
else
{
if (isset($args['children']) && !$args['children'])
{
$children = $node->children();
foreach ($node->children() as $child)
{
if ($child->name() == 'ul') {
$node->removeChild($child);
}
}
}
}
if (($node->name() == 'li') && ($id = $node->attributes('id'))) {
if ($node->attributes('class')) {
$node->addAttribute('class', $node->attributes('class').' item'.$id);
} else {
$node->addAttribute('class', 'item'.$id);
}
}
if (isset($path) && $node->attributes('id') == $path[0]) {
$node->addAttribute('id', 'current');
} else {
$node->removeAttribute('id');
}
$node->removeAttribute('level');
$node->removeAttribute('access');
}
define('modMyMainMenuXMLCallbackDefined', true);
}
ob_start();
modMainMenuHelper::render($params, 'modMyMainMenuXMLCallback');
$menu_html = ob_get_contents();
ob_end_clean();
if($params->get('menutype')=="mainmenu"){
$tag = $params->get('tag_id');
}
//output the menu!
echo fancyMenuPatch($menu_html,$tag);
?>