我正在尝试在我的joomla模板中实现自定义菜单。我在index.php
<?php include(dirname(__FILE__).DS.'/navi.php'); ?>
navi.php
看起来像这样
<?php
defined( '_JEXEC' ) or die( 'Restricted access');
$db = &JFactory::getDBO();
$query = "SELECT * FROM jos_menu WHERE menutype='mainmenu' AND published='1' AND sublevel='0' AND access='0' ORDER BY ordering ASC;";
$db->setQuery($query);
$navi = $db->loadAssocList();
$menu = &JSite::getMenu();
$active = $menu->getActive();
foreach ($navi as $item) {
if ($item['id'] == $active->id) {
$open = ' class="open"';
} else {
$open = '';
}
echo '<li'.$open.'><a href="'.$item['link'].'">'.$item['name'].'</a></li>';
}
?>
问题是$active
变量仅在首页打开时包含数据。这段代码出了什么问题?
谢谢!
答案 0 :(得分:0)
发现错误:您需要一种不同的方法来确定菜单项的网址:
$url = JRoute::_($item['link'].'&Itemid='.$item['id']);
echo '<li'.$open.'><a href="'.$url.'">'.$item['name'].'</a></li>';
谢谢!