简体   繁体   English

在foreach中的Joomla 3菜单php中找到第二个li子菜单

[英]Joomla 3 menu php in foreach find second li submenu

in Joomla menu module php - default.php,How can i find the second li submenu and add class name 'the-secondsubmenu' into it? 在Joomla菜单模块php-default.php中,如何找到第二个li子菜单,并在其中添加类名'the-secondsubmenu'?

the output will looks like this: 输出将如下所示:

<ul class="nav"> 
    <li>

            <a></a> 
            <ul>
                <li class="the-secondsubmenu">
                    <a></a>
                </li>
            </ul> 

    </li>
</ul>

i'm add this line in foreach 我在foreach中添加此行

if($item->level < 2): $counter += count($item); endif;

and add these 并添加这些

if ($item->deeper)
{
    $class .= ' deeper';
}
elseif($item->deeper && $counter === 2){

    $class .= ' deeper the-secondsubmenu';
}

THE PHP PHP

foreach ($list as $i => &$item)
{
    if($item->level < 2):
        $counter += count($item);
    endif;

    $class = 'item-' . $item->id;

    if (($item->id == $active_id) OR ($item->type == 'alias' AND $item->params->get('aliasoptions') == $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';
    }
    elseif($item->deeper && $counter === 0){

        $class .= ' deeper the-secondsubmenu';
    }

these code not working, 这些代码不起作用,
As always, your assistance is appreciated! 一如既往地感谢您的协助!

if you write this code, the second part won't be executed because the test includes the same test as the first block. 如果您编写此代码,则第二部分将不会执行,因为该测试包含与第一块相同的测试。

if ($item->deeper) {
    $class .= ' deeper';
}
elseif ($item->deeper && $counter === 2) {
    $class .= ' deeper the-secondsubmenu';
}

maybe you should try to put the second block first : 也许您应该尝试将第二个块放在第一位:

if ($item->deeper && $counter === 2) {
    $class .= ' deeper the-secondsubmenu';
}
elseif ($item->deeper) {
    $class .= ' deeper';
}

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

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