Joomla! provides four menu types by default
- list
- legacy_horizantal
- legacy_vertical
- legacy_flat
However if some one wants to add new menu type to the predefined menu types in joomla backend, this tutorial guides them through it easily. It involves only three steps and is tested on Joomla! 1.5
In this tutorial we will add new menu type to our joomla mod_mainmenu and name it test_type. To add custom menu type to Joomla! 1.5 mod_mainmenu, please follow these steps (make sure to backup the mod_mainmenu folder out side joomla directory – donot save the copy in the same modules folder – before attempting to follow the tutorial to save you from any trouble in future):
1. Add custom new menu type to Joomla administration module manager:
In first step we will define a new custom menu type to be listed and shown in the Joomla! administration backend module manager with the list of other four already existing joomla menu types. To do so:
-> Goto> modules > mod_mainmenu
-> Edit mod_mainmenu.xml and add the code <option value=”test_type”>test-type</option> like this:
<param name="menutype" type="mos_menu" default="" label="Menu Name" description="The name of the menu (default is mainmenu)" /> <param name="menu_style" type="list" default="list" label="Menu Style" description="The menu style"> <option value="list">List</option> <option value="vert_indent">Legacy - Vertical</option> <option value="horiz_flat">Legacy - Horizontal</option> <option value="list_flat">Legacy - Flat List</option> <option value="test_type">test-type</option> </param>
And save the file. This will now show the name test-type in the drop down of the module manager menu manager along with already defined joomla 1.5 types.
2. Edit: helper.php
Next step involves editing helper.php in the modules > mod_mainmenu folder.
In this file, we will define a case for the new custom type that we just defined in the menu type select drop down in the above step for Joomla! 1.5 administration module manager.
Goto the helper.php and find this part of code and enter after this code the part in bold below:
function render(&$params, $callback) { switch ( $params->get( 'menu_style', 'list' ) ) { case 'list_flat' : // Include the legacy library file require_once(dirname(__FILE__).DS.'legacy.php'); mosShowHFMenu($params, 1); break; case 'horiz_flat' : // Include the legacy library file require_once(dirname(__FILE__).DS.'legacy.php'); mosShowHFMenu($params, 0); break; case 'vert_indent' : // Include the legacy library file require_once(dirname(__FILE__).DS.'legacy.php'); mosShowVIMenu($params); break; case 'test_type' : // Include the legacy library file require_once(dirname(__FILE__).DS.'legacy.php'); mosShowttMenu($params, 0); break;
3. Edit: legacy.php
Now we will be editing the legacy.php in the mod_mainmenu folder of the modules folder. In legacy.php file, we will simply copy all of the code that is inside any previous menutype declaration and just rename the function to our own name and edit the code in it as we want like this:
Copy the function for horizonatal type there e.g.
/** * Draws a horizantal style menu (very simple case) */ function mosShowHFMenu(& $params, $style = 0) { $menu = & JSite::getMenu(); $user = & JFactory::getUser(); //get menu items . . }
and paste it just below it and just rename the function name from mosShowHFMenu to mosShowttMenu like this:
/** * Draws a test type menu (very simple case) */ function mosShowttMenu(& $params, $style = 0) { $menu = & JSite::getMenu(); $user = & JFactory::getUser(); //get menu items . . }
You can edit this copied function upto your code needs that how you want this new custom menu type to deliver the menu code.
Hope it helps, do let me know if you need any help regarding this or have any trouble in customizing it.
A Great way to add Custom Title in a joomla. Its work with every template thats too coool
umm… custom title??? sorry i didn’t get what you mean?
Cool what you blogged about realli made my day! (ok i know u must think im a crazy haha!) Sorry for my poor english!
I am glad to know that it helped sir :)
Thanks for the information because I have spent several days trying to find a a way to modify the legacy menu types to create a drop down select menu that works with noixacl. I have previously used “extended menu” module to create a custom select list but his module does not work with NoixACL and there are no adapters for it that I can find.
I wonder, could anyone please assist and help me out.
I would need the required code for legacy.php to deliver a menu that creates a standard javascript type form pull down selection menu.
If you could help that would be much appreciated.
it will definitely be a pleasure to help you out!
Please let me know any example webpage so that i can have a clear idea of what type of menu you want to be generated.
Something similar to this but this does not create working links with the present blank option value. What should go inside the option value to create working links?
function mosShowDTMenu(& $params, $style = 0)
{
$menu = & JSite::getMenu();
$user = & JFactory::getUser();
//get menu items
//open form
echo ”;
echo ”;
echo ‘Select Class Tools’;
//generate links
$menuclass = ‘mainlevel’ . $params->get(‘class_sfx’);
$lang =& JFactory::getLanguage();
$rows = $menu->getItems(‘menutype’, $params->get(‘menutype’));
foreach ($rows as $row)
{
if ($row->access get(‘aid’, 0)) {
echo ” . mosGetMenuLink($row, 0, $params);
// echo ” . mosGetMenuLink($row, 0, $params);
}
}
echo ”;
echo ‘ ‘;
//end form
}
//END CUSTOM CODE
I will have a look at it and create a dropdown (select based) menu code for you soon. (i hope it’s not very urgent?)
That’s wonderful. Shukran.
You’re welcome :)
HI Nabeel,
What will happen to that mod_mainmenu customisation, if anyone update joomla. ?????
if the update includes update to mod_mainmenu, then it will be overwritten
you can backup the mod_mainmenu folder and replace it back once update has been done.
Would it be possible to copy mainmenu and create a completely new module that included the additional menu type?
yes it is possible
you need to rename the folder and file names from mainmenu to custommenu etc and also edit the xml file to change all the file and item names in it
once done that, you need to “install” this new module from extension manager and then use it
Please note, this is possible, but it may still conflict with the existing mainmenu module as functions and classes being used by them would be same. If you want to do so, it may need some work to rename all the classes being used and fix the conflicts.
You simply rock my world!
So simple yet so brilliant fix!
Cheers!
//Varmer
I have previously used “extended menu” module to create a custom select list but his module does not work with NoixACL and there are no adapters for it that I can find.
were you able to make them manually? let me know if you want me to do it for you on your Joomla site!
Thanks. Nice article.
Welcome Jayendra :) glad that it helped you with your Joomla site!
Keep on working, great job!
thanks for appreciating :)