简体   繁体   English

如何在Joomla 3 default.php文件中更改菜单类以模仿自定义菜单类

[英]How to change the menu classes in Joomla 3 default.php file to mimic custom menu classes

Ok the background on this is as follows: 1. I want the joomla menu nav to switch from its default classes to my custom classes and add an tag for the pages active menu item (if neccessary) 好的,其背景如下:1.我希望joomla菜单导航从其默认类切换到我的自定义类,并为页面活动菜单项添加标签(如有必要)

The default classes in the default.php file is this default.php文件中的默认类是这个

<ul class="nav menu<?php echo $class_sfx;?>"<?php
$tag = '';

if ($params->get('tag_id') != null)
{
    $tag = $params->get('tag_id') . '';
    echo ' id="' . $tag . '"';
}
 ?>>
 <?php
 foreach ($list as $i => &$item)
 {
$class = 'item-' . $item->id;

if ($item->id == $active_id)
{
    $class .= ' current';
}

if (in_array($item->id, $path))
{
    $class .= ' active';
}
elseif ($item->type == 'alias')
{
    $aliasToId = $item->params->get('aliasoptions');

    if (count($path) > 0 && $aliasToId == $path[count($path) - 1])
    {
        $class .= ' active';
    }
    elseif (in_array($aliasToId, $path))
    {
        $class .= ' alias-parent-active';
    }
}

if ($item->type == 'separator')
{
    $class .= ' divider';
}

if ($item->deeper)
{
    $class .= ' deeper';
}

if ($item->parent)
{
    $class .= ' parent';
}

if (!empty($class))
{
    $class = ' class="' . trim($class) . '"';
}

echo '<li' . $class . '>';

// Render the menu item.
switch ($item->type) :
    case 'separator':
    case 'url':
    case 'component':
    case 'heading':
        require JModuleHelper::getLayoutPath('mod_menu', 'default_' .                                                 $item->type);
        break;

    default:
        require JModuleHelper::getLayoutPath('mod_menu', 'default_url');
        break;
endswitch;

// The next item is deeper.
if ($item->deeper)
{
    echo '<ul class="nav-child unstyled small">';
}
elseif ($item->shallower)
{
    // The next item is shallower.
    echo '</li>';
    echo str_repeat('</ul></li>', $item->level_diff);
}
else
{
    // The next item is on the same level.
    echo '</li>';
}
 }
 ?></ul>

the output via browser is this 通过浏览器的输出是这个

<ul class="nav menu">
<li class="item-101 current active"><a href="/">Home</a></li></ul>

the output I would like it to be is this... 我想要的输出是这个...

 <ul class="title-area">
    <li class="name">
    <h1><a href="#">My Site</a></h1>
  </li>
 </ul>

My brute intution would tell me to change the nav to title-area but I am unsure of how to incorporate "name" into the li structure. 我的直觉会告诉我将导航更改为标题区域,但是我不确定如何将“名称”合并到li结构中。

Moreover, I am assuming the tag is only for the page that is active or present at the moment... This would be nice to incorporate as well... as my foundation css structure has the line height already assigned to that structure of html. 此外,我假设标记仅适用于当前处于活动状态或当前存在的页面...也可以很好地结合...因为我的基础css结构的行高已经分配给了html的那个结构。

help is appreciated. 帮助表示赞赏。

Ok after testing I have figured out the proper answer. 确定测试后,我已经找到正确的答案。 Now this solution is in general and should work well for any menu and dropdown menu structure within Joomla's default menu system. 现在,此解决方案已大体上适用于Joomla默认菜单系统中的任何菜单和下拉菜单结构。

I have complete this solution with Foundation 5 menu setup (later I will try a different menu system but the idea should be the same). 我已经通过Foundation 5菜单设置完成了此解决方案(稍后,我将尝试使用其他菜单系统,但想法应该相同)。

For the menu module go to the default.php located here: /modules/mod_menu/tmpl 对于菜单模块,请访问位于以下位置的default.php:/ modules / mod_menu / tmpl

The default setting has a class structure of nav menu as such: 默认设置具有导航菜单的类结构,如下所示:

<ul class="nav menu<?php echo $class_sfx;?>"<?php
$tag = '';

Change the class to be what you need the class structure to be. 将类更改为您需要的类结构。 if you are 100% circumventing the Joomla css (bootstrap) file structure then you can change it... or if not you can just add a class name(s) that you need. 如果您100%绕过Joomla css(引导程序)文件结构,则可以对其进行更改...否则,您可以添加所需的类名。

here is what mine changed to: 这是我的变为:

<ul class="right nav menu<?php echo $class_sfx;?>"<?php
$tag = '';

Now if you are following your new menu system's class structure (Foundation) you might need to designate a class for <li and for the sub menu items ie for a dropdown menu. 现在,如果您遵循新菜单系统的类结构(Foundation),则可能需要为<li和子菜单项(即下拉菜单)指定一个类。

***Keep in mind that for Joomla's menu structure within PHP it pulls the item number and if it is the current page it will auto mark it as auto (automatically)... so no need to add that in except for the class you are adding. ***请记住,对于PHP中的Joomla菜单结构,它会拉出项目编号,如果它是当前页面,它将自动将其标记为自动(自动)...因此,除了您需要的类之外,无需在其中添加它正在添加。 Edit* Adding the class "has-dropdown" should be for the parent 编辑*添加类“ has-dropdown”应该用于父类

so on this line (the before): 所以在这行(之前):

if ($item->parent)
{
    $class .= ' parent';
}

Change it to this (the after): 更改为此(以下):

if ($item->parent)
{
    $class .= ' has-dropdown parent';
}

As well the sub child items need to change. 子项也需要更改。

So on this line (the before): 因此,在此行(之前):

// The next item is deeper.
if ($item->deeper)
{
 echo '<ul class="nav-child unstyled small">';
}

Change it to this (the after): 更改为此(以下):

// The next item is deeper.
if ($item->deeper)
{
    echo '<ul class="dropdown nav-child unstyled small">';
}

I think it would be great to add a plug-in that can mod the backend menu setup to include class to add to or change for <ul and <li for both menu and sub menu child items. 我认为,添加一个可以修改后端菜单设置以包含要添加或更改的<ul<li菜单和子菜单子项的类的插件,将是很好的。

Hopefully this helps someone... I will add more later. 希望这对某人有所帮助...我稍后会再添加。

*I have one error I am getting with this and the Foundation menu I am using. *我在使用此菜单以及使用的Foundation菜单时遇到一个错误。 The first child will show but if that child has a child menu item it won't show... So there's that fix still needed. 第一个孩子将显示,但如果该孩子有一个子菜单项,则不会显示...所以仍然需要该修复程序。

*remember to change the setting: Show Sub-menu Items to "yes" *请记住要更改设置:将子菜单项显示为“是”

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

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