I’m trying to implement a custom menu in my joomla template. I added this line at the desired position in my index.php
<?php include(dirname(__FILE__).DS.'/navi.php'); ?>
the navi.php looks like this
<?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>';
}
?>
The problem is that the $active variable only contains data when the frontpage is open. What’s wrong with this code?
Thank you!
Found the bug: you need a different method to determine the url of the menu item:
Thank you!