Joomla 主菜单 html 输出

标签 joomla joomla1.5

我正在尝试编辑输出 joomla main_menu 模块,以便制作自定义下拉菜单。目前它当前输出的html是这样的:

<ul class="menu">
<li class="active item1" id="current"><a href="#"><span>First Level Item </span</a></li>  
<li class="parent item63"><a href="#"><span>First Level Item Parent</span></a>
<ul>
  <li class="item60"><a href="#"><span>Second Level Item</span></a></li>
  <li class="item69"><a href="#"><span>Second Level Item</span></a></li>
</ul>
</li>
<li class="item64"><a href="#"><span>First Level Item</span></a></li>
<li class="item66"><a href="#"><span>First Level Item</span></a></li>

我想做的是删除输出的跨度标签。

到目前为止我所知道的是,如果我想编辑输出;在我的模板文件夹中,我创建了一个名为“html”的目录,然后在该目录中创建了一个名为“mod___mainmenu”的新目录,然后从模块目录中的现有 mod_mainmenu 文件夹中复制 default.php 文件。我为获取文件所做的所有更改都会更改输出。

我遇到的问题是我无法理解 default.php 文件中编写的代码发生了什么,因为它使用了一些我不熟悉的 XML 系统并且没有注释。

如果有人有任何想法会非常有帮助!

这是菜单的 default.php 文件中的代码:
defined('_JEXEC') or die('Restricted access');


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))
    {
        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('modMainMenuXMLCallbackDefined', true);
}
modMainMenuHelper::render($params, 'modMainMenuXMLCallback');

最佳答案

您应该尽可能避免编辑核心文件,以避免在升级时覆盖您的更改。请改用模板覆盖文件。

当我遇到这个问题时,我想为每个菜单项添加并清空 em 标签以允许 Gilder/Levin image replacement .在我的 html 覆盖 ({templatedir}\html\mod_mainmenu\default.php) 中,我用输出缓冲区包围了对 modMainMenuHelper::render 的调用(基本上是最后一行),并使用了一个简单的 str_replace 来添加 em 标签:

ob_start();
modMainMenuHelper::render($params, 'modMainMenuXMLCallback');
$mainMenuContent = ob_get_clean();
echo str_replace('</span>', '</span><em></em>', $mainMenuContent);

由于您只想摆脱 span 标签,您可以这样做:
ob_start();
modMainMenuHelper::render($params, 'modMainMenuXMLCallback');
$mainMenuContent = ob_get_clean();
echo str_replace(array('<span>','</span>'), array('',''), $mainMenuContent);

关于Joomla 主菜单 html 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/398476/

相关文章:

php - 使用 Cron Job 每分钟更新一次表格行

css - 有条件的 IE 评论在 Joomla 中不起作用

Drupal 或 Joomla 表单生成器

joomla - 如何在 Joomla 1.7 中使用 JDatabaseQuery 编写查询?

html - 'li' + float 使 Internet Explorer 6 崩溃

html - 无法理解为什么表格带有双边框。

joomla - 如何将 JS/CSS 文件添加到 Joomla 模块?

ssl - Xampp bitnami joomla ssl

html - Joomla Ari 分机菜单在 Internet Explorer 7 中显示为垂直

php - 哪个Joomla版本低于2并且接近1.5。支持 PHP 5.4 吗?