这是我刚刚制作的一个模块。它从您选择的菜单项中呈现子菜单项。在此处下载插件:下载
如果您无法下载或出现问题,这里是插件文件:
PHP 文件 ( mod_submenu.php
):
<ul class="menu">
<?php
defined('_JEXEC') or die;
$m = JFactory::getApplication()->getMenu();
$active = $m->getActive();
$active_id = isset($active) ? $active->id : $m->getDefault()->id;
$path = isset($active) ? $active->tree : array();
$menu = $m->getMenu();
$parentId = $params->get("menuitem");
foreach($menu as $item){
if($item->level == 2 && $item->parent_id == $parentId){
$class = 'item-'.$item->id;
if ($item->id == $active_id) {
$class .= ' current';
}
if (in_array($item->id, $path)) {
$class .= ' active';
}
$flink = $item->link;
if ((strpos($item->link, 'index.php?') === 0) && (strpos($item->link, 'Itemid=') === false)) {
$item->flink = $item->link.'&Itemid='.$item->id;
if (strcasecmp(substr($item->flink, 0, 4), 'http') && (strpos($item->flink, 'index.php?') !== false)) {
$item->flink = JRoute::_($item->flink, true, $item->params->get('secure'));
}
else {
$item->flink = JRoute::_($item->flink);
}
}
echo "<li class='$class'><a href='$item->flink'>$item->title</a></li>";
}
}
?>
</ul>
XML 文件 ( mod_submenu.xml
):
<?xml version="1.0" encoding="utf-8"?>
<extension type="module" version="2.5.0" client="site" method="install">
<name>Show Submenu</name>
<author>Brian</author>
<creationDate>2012</creationDate>
<copyright></copyright>
<license>No license</license>
<authorEmail>No email</authorEmail>
<authorUrl>No website</authorUrl>
<version>1.0.0</version>
<description>Showing a submenu</description>
<files>
<filename module="mod_submenu">mod_submenu.php</filename>
<filename>index.html</filename>
</files>
<config>
<fields name="params">
<fieldset name="basic">
<field
name="menuitem"
type="menuitem"
label="Choose the menuitem" />
</fieldset>
</fields>
</config>
</extension>
(请原谅格式,我还是要习惯 SO)
还有一个空白的 index.html 文件。将它们全部放在一个名为mod_submenu
, zip 的文件夹中,安装并配置它!
配置:
结果: