J3.x

Difference between revisions of "Creating a submenu"

From Joomla! Documentation

(Corrected 'dashes' to 'hyphens' and other markup changes.)
 
(43 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{page|needs review|Images out of date, need 3.x images.}}
+
<noinclude><languages /></noinclude>
 
{{Top portal heading|color=white-bkgd|icon=magic|icon-color=#5091cd|size=3x|text-color=#333|title=Tutorial<br />
 
{{Top portal heading|color=white-bkgd|icon=magic|icon-color=#5091cd|size=3x|text-color=#333|title=Tutorial<br />
How to Create a Submenu in a Joomla! Site}}
+
<translate><!--T:1-->
In Joomla!, submenus can be shown either as one menu with two or more levels or as completely separate menu modules. This is useful for constructing drop-down menus and for showing sublevel menu items in separate positions on your template. To show how to do this, we will step through creating parent level menu items and sublevel menu items and then see how to show those items either within one large menu with drop-down navigation or as separate parent and child items. {{-}}
+
How to Create a Submenu in a Joomla! Site</translate>}}
<br />
+
<noinclude>{{Joomla version|version=3.x}}</noinclude>
For this tutorial, begin by logging into the Joomla Administrator. If you are unfamiliar with how to login see this article: https://docs.joomla.org/J3.x:Logging_in_or_out_of_the_Administrator_back-end. {{-}}
+
<translate><!--T:2-->
<br />
+
In Joomla, submenus can be shown either as one menu with two or more levels or as completely separate menu modules. This is useful for constructing menus showing parent and child level navigation or for showing sublevel menu items in entirely separate positions on your template. To show how to do this, we will step through creating parent and child level menu items and then see how to show those items within one large menu and as a separate menu with only the child level items showing in a separate position on a template.</translate> {{-}}
Please note, for this tutorial you need Super Administrator privileges or privileges open enough to create and modify Articles, Menu Items, and Modules. For more information on User Access Control see this article: https://docs.joomla.org/J3.x:Access_Control_List_Tutorial
+
__TOC__
 +
<translate><!--T:3-->
 +
To begin, menus function with three basic constructs:</translate>
 +
<translate><!--T:4-->
 +
*Articles - you need content to link to. This can also be component pieces, other menu items or external links.</translate>
 +
<translate><!--T:5-->
 +
*Menu - describes the menu items, the type of navigation, their parent/child relationship to other menu items and the order they are displayed in.</translate>
 +
<translate><!--T:6-->
 +
*Menu Module - controls the position and displaying of the menu.</translate>
  
==Step 1 - Create Your Articles==
+
<translate><!--T:7-->
In our example, we will create top level menu items for "Dogs" and "Cats". Under Dogs, we will have "Collies" and "Pomeranians". Under Cats we will have "Burmese" and "Russian Blues". So the structure of the our sample menu items will be as follows:
+
For this tutorial, begin by logging into the Joomla Administrator. If you are unfamiliar with how to login see this article: [[S:MyLanguage/J3.x:Logging_in_or_out_of_the_Administrator_back-end|Logging in or out of the Administrator backend]].</translate> {{-}}
  
*Dogs
+
<translate><!--T:8-->
**Collies
+
'''Note''' For this tutorial you need Super Administrator permissions or permissions open enough to create and modify Articles, Menu Items, and Modules. For more information on User Access Control see [[S:MyLanguage/J3.x:Access Control List Tutorial|ACL Tutorial]].</translate>
**Pomeranians
 
*Cats
 
**Burmese
 
**Russian Blues
 
  
First, create 4 articles so our menu items will have something to link to: "Collies", "Pomeranians", "Burmese" and "Russian Blue". See this tutorial if you need help creating an Article: https://docs.joomla.org/Adding_a_new_article
+
<translate>
 +
==Step 1 - Create Your Articles== <!--T:9-->
 +
</translate>
 +
<translate><!--T:10-->
 +
In our example, we will create top level menu items for ''Dogs'' and ''Cats''. Under Dogs, we will have ''Collies'' and ''Pomeranians''. Under Cats we will have ''Burmese'' and ''Russian Blues''. So the structure of our sample menu items will be as follows:</translate>
  
==Step 2 - Create the Parent Level Menu Items==
+
<translate><!--T:11-->
To create the structure, we need to navigate to the menu where we want our new menu items. If this is a new menu, you will need to create it. See this tutorial on how to create a menu: https://docs.joomla.org/J3.x:Adding_a_new_menu. {{-}}
+
*Dogs</translate>
<br />
+
<translate><!--T:12-->
Once you have your menu located in the Menu Manager, you will add the parent menu items using the '''System Links &rarr; External URL''' for each navigation link: "Dogs" and "Cats". {{-}}
+
**Collies</translate>
<br />
+
<translate><!--T:13-->
Please note, there are other menu item types that can be used for the parent level navigation structure. 
+
**Pomeranians</translate>
 +
<translate><!--T:14-->
 +
*Cats</translate>
 +
<translate><!--T:15-->
 +
**Burmese</translate>
 +
<translate><!--T:16-->
 +
**Russian Blues</translate>
  
Here are the steps to create sample Menu Items using our example data. For more information on creating Menu Items go here: https://docs.joomla.org/Adding_a_new_menu_item {{-}}
+
<translate><!--T:17-->
1. Navigate to the Menu Manager by clicking on '''Menus &rarr; Menu Manager'''
+
First, create 4 articles so our menu items will have something to link to: ''Collies'', ''Pomeranians'', ''Burmese'' and ''Russian Blue''. See this tutorial if you need help creating an Article: [[S:MyLanguage/Help34:Content Article Manager Edit|Adding a new Article]].</translate>
[[Image:J3x-Edit-Main-Menu-en.jpg]]
 
  
2. In the toolbar, click on "New"
+
<translate>
[[Image:J3x-Edit-Main-Menu-Toolbar-new-en.png]]
+
==Step 2 - Create the Parent Level Menu Items== <!--T:18-->
 +
</translate>
 +
<translate><!--T:19-->
 +
To create the structure, we need to navigate to the menu where we want our new menu items. If this is a new menu, you will need to create it. See this tutorial on how to create a menu: [[S:MyLanguage/J3.x:Adding a new menu|Adding a new menu]].</translate>
  
3. For the purposes of this exercise we are creating "placeholder" links using the '''System &rarr; External URL''' menu type for the "Dogs" and "Cats" parent level menu items.{{-}} So, in the new Menu Item click on the Menu Type select button:
+
<translate><!--T:20-->
[[Image:J3x-Add-Main-Menu-Select-Type-en.png]]
+
Once you have your menu located in the Menu Manager, you will add the parent menu items using the {{rarr|System Links,External URL}} for each navigation link: ''Dogs'' and ''Cats''.</translate>
  
4. Click on "System Links" then scroll down and select "External URL".
+
<translate><!--T:21-->
[[Image:J3x-Create-Sublevel-Menu-System-External-Url-en.png]]
+
Please note, there are other menu item types that can be used for the parent level navigation structure.</translate>
  
5. Add the '''Menu Item Title''' ( "Dogs" ) and type in a hashtag "#" in the '''Link''' box.
+
<translate><!--T:22-->
[[Image:J3x-Create-Sublevel-Menu-Menu-Item-External-Url-en.png]]
+
Here are the steps to create sample Menu Items using our example data. For more information on creating Menu Items see [[S:MyLanguage/J3.x:Adding a new menu|Adding a new menu item]].</translate> {{-}}
 +
<translate><!--T:23-->
 +
# Navigate to the Menu Manager by clicking on {{rarr|Menus,Menu Manager}}</translate>{{-}}[[Image:J3x-Edit-Main-Menu-<translate><!--T:24-->
 +
en</translate>.jpg|775px|border]]
 +
<translate><!--T:25-->
 +
# In the toolbar, click on ''New''</translate>{{-}}[[Image:J3x-Edit-Main-Menu-Toolbar-new-<translate><!--T:26-->
 +
en</translate>.png|775px|border]]
 +
<translate><!--T:27-->
 +
# For the purposes of this exercise we are creating "placeholder" links using the {{rarr|System,External URL}} menu type for the ''Dogs'' and ''Cats'' parent level menu items. So, in the new Menu Item, click on the Menu Type select button:</translate> {{-}}[[Image:J3x-Add-Main-Menu-Select-Type-<translate><!--T:28-->
 +
en</translate>.png|775px|border]]
 +
<translate><!--T:29-->
 +
# Click on ''System Links'' then scroll down and select ''External URL''.</translate>{{-}}[[Image:J3x-Create-Sublevel-Menu-System-External-Url-<translate><!--T:30-->
 +
en</translate>.png|775px|border]]
 +
<translate><!--T:31-->
 +
# Add the ''Menu Item Title'' ("Dogs") and type in a hashtag "#" in the ''Link'' box.</translate>{{-}}[[Image:J3x-Create-Sublevel-Menu-Menu-Item-External-Url-<translate><!--T:32-->
 +
en</translate>.png|775px|border]]
 +
<translate><!--T:33-->
 +
# Save your menu item.</translate> {{-}}[[Image:Joomla-3-Menu-Add-Menu-Save-<translate><!--T:34-->
 +
en</translate>.png|775px|border]]
 +
<translate><!--T:35-->
 +
# Repeat steps 2 - 6 for the ''Cats'' Parent Level menu item.</translate>
  
6. Save your menu item. {{-}}
+
<translate>
[[Image:Joomla-3-Menu-Add-Menu-Save-en.png]]
+
==Step 3 - Create the Sublevel Menu Items== <!--T:36-->
 +
</translate>
 +
<translate><!--T:37-->
 +
Now you will add the sublevel menu items using the {{rarr|Articles,Single Article}} to create menu links to the individual pages ''Collies'', ''Pomeranians'', ''Burmese'', and ''Russian Blues''. For each Menu Item created, we will set the ''Parentage'' to ''Dogs'' or ''Cats''.</translate>
  
7.  Repeat steps 2 - 6 for the "Cats" Parent Level menu item.
+
<translate><!--T:38-->
 +
For more detailed information on how to create a Single Article Menu Type, see [[S:MyLanguage/Adding a menu item which points to an Article|Adding a menu item which points to an Article]].</translate>
  
==Step 3 - Create the Sublevel Menu Items==
+
<translate><!--T:39-->
Now you will add the sublevel menu items using the '''Articles &rarr; Single Article''' to create menu links to the individual pages "Collies", "Pomeranians", "Burmese", and "Russian Blues". For each Menu Item created, we will set the '''Parentage''' to "Dogs" or "Cats". {{-}} <br />
+
'''Note''' There are other menu item types that can be used for the sublevel navigation structure.</translate>
For more detailed information on how to create a Single Article Menu Type click here: https://docs.joomla.org/Adding_a_menu_item_which_points_to_an_Article {{-}} Please note, there are other menu item types that can be used for the sublevel navigation structure.
 
  
1. In the toolbar, click on "New".
+
<translate><!--T:40-->
[[Image:J3x-Edit-Main-Menu-Toolbar-new-en.png]]
+
# In the toolbar, click on "New".</translate>{{-}}[[Image:J3x-Edit-Main-Menu-Toolbar-new-<translate><!--T:41-->
 +
en</translate>.png|775px|border]]
 +
<translate><!--T:42-->
 +
# In the new Menu Item click on the Menu Type select button:</translate>{{-}}[[Image:J3x-Add-Main-Menu-Select-Type-<translate><!--T:43-->
 +
en</translate>.png|775px|border]]
 +
<translate><!--T:44-->
 +
# Select {{rarr|Articles,Single Article}} from the list displayed.</translate>{{-}}[[Image:J3x-Add-Main-Menu-Article-Type-<translate><!--T:45-->
 +
en</translate>.png|border]]
 +
<translate><!--T:46-->
 +
# Returning to the Menu Item Detail page, click on the ''Select Article'' List.</translate>{{-}}[[Image:J3x-Add-Main-Menu-Article-Select-Article-<translate><!--T:47-->
 +
en</translate>.png|border]]
 +
<translate><!--T:48-->
 +
# Select the ''Collies'' article for this example.</translate>{{-}}[[Image:J3x-Create-Sublevel-Menu-Menu-Item-Single-Article-<translate><!--T:49-->
 +
en</translate>.png|border]]
 +
<translate><!--T:50-->
 +
# On returning to the Article Detail page, fill in the ''Menu Item Title''.</translate> <translate><!--T:51-->
 +
Then click on the ''Parent Item'' select list located in the far right column. Find and select the ''Dogs'' parent item by scrolling through the Parent Item List. Note that menu levels are displayed with hyphens: "-" (single hyphen) is the highest level, "--" (two hyphens) is the second level, "---" third level and so on.</translate> {{-}}[[Image:J3x-Create-Sublevel-Menu-Select-Parent-Item-<translate><!--T:52-->
 +
en</translate>.png|775px|border]]
 +
<translate><!--T:53-->
 +
# Click on the button ''Save & Close'' up in the top button.</translate>{{-}}[[Image:Joomla-3-Menu-Add-Menu-Save-<translate><!--T:54-->
 +
en</translate>.png|775px|border]]
 +
<translate><!--T:55-->
 +
# Repeat steps 1-7 for the remaining articles ''Pomeranians'' with the ''Dog'' parent and articles ''Burmese'' and ''Russian Blues'' for the ''Cat'' parent.</translate>
 +
<translate><!--T:56-->
 +
# When you are finished with the "Menu Items" section, the Menu Item Manager should look very similar to the following:</translate>{{-}}[[Image:J3x-Create-Sublevel-Menu-Items-<translate><!--T:57-->
 +
en</translate>.png|775px|border]]
  
2. In the new Menu Item click on the Menu Type select button:
+
<translate>
[[Image:J3x-Add-Main-Menu-Select-Type-en.png]]
+
==Step 4 - Setup the Menu Module== <!--T:58-->
 +
</translate>
 +
<translate><!--T:59-->
 +
At this point, we have our Articles and Menu Items done. Now we need to update the ''Menu Module''. In Joomla!, the Menu Module determines three things:</translate>
 +
<translate><!--T:60-->
 +
# What the menu looks like.</translate>
 +
<translate><!--T:61-->
 +
# Where on the page it will show.</translate>
 +
<translate><!--T:62-->
 +
# Which pages it will show on.</translate>
  
3. Select '''Articles &rarr; Single Article''' from the list displayed.{{-}}
+
<translate><!--T:63-->
[[Image:J3x-Add-Main-Menu-Article-Type-en.png]]
+
We will do two examples:</translate>
 +
<translate><!--T:64-->
 +
* In the first example, we will set the parameters that show the parent level menu items with the lower level items beneath.</translate>
 +
<translate><!--T:65-->
 +
* In the second example, we will add an additional menu module that appears in the left column and shows only the second level menu items.</translate>
 +
<translate><!--T:66-->
 +
'''Note''' We will do both examples using the Protostar Template included in the core Joomla! installation.</translate>
  
4. Returning to the Menu Item Detail page, click on the '''Select Article''' List.{{-}}
+
<translate>
[[Image:J3x-Add-Main-Menu-Article-Select-Article-en.png]]
+
===Example 1 - One Menu Module With Second Level Menu Items=== <!--T:67-->
 +
</translate>
 +
<translate><!--T:68-->
 +
To show this as one module, follow these steps:</translate>
 +
<translate><!--T:69-->
 +
# Navigate to {{rarr|Extensions,Module Manager}} and locate the Menu Module associated with your menu. For instructions on creating a new menu module, see</translate> [[S:MyLanguage/Help34:Extensions Module Manager Menu|Module Menu]] {{-}}[[Image:J3x-Create-Sublevel-Menu-Module-Control-Panel-<translate><!--T:70-->
 +
en</translate>.png|775px|border]]
 +
<translate><!--T:71-->
 +
# Click on the module name associated with your menu. In this tutorial, we are selecting ''Main Menu''. ''Note:'' this image has been filtered by selecting ''Menu'' in the Module type dropdown.</translate>{{-}}[[Image:J3x-Create-Sublevel-Menu-Module-List-Menus-<translate><!--T:72-->
 +
en</translate>.png|775px|border]]
 +
<translate><!--T:73-->
 +
# In the Module details, set the ''Start level'' to ''1'', the ''End Level'' to ''All'' and set ''Show Submenu Items'' to ''Yes''.</translate>{{-}}[[Image:J3x-Create-Sublevel-Menu-Module-Details-<translate><!--T:74-->
 +
en</translate>.png|775px|border]]
 +
<translate><!--T:75-->
 +
# For this tutorial, we have added some styling in the ''Advanced'' tab. In the ''Menu Class Suffix'' we have entered ''navbar-nav nav-pills''. You can also add ''navbar-nav nav-tabs'' for a slightly different look. Note: there is a space before ''navbar-nav''.</translate>{{-}}[[Image:J3x-Create-Sublevel-Menu-Module-Advanced-Menu-Class-Suffix-<translate><!--T:76-->
 +
en</translate>.png|border]]
 +
<translate><!--T:77-->
 +
# Click on ''Save & Close''.</translate>{{-}}[[Image:J3x-Create-Sublevel-Menu-Module-Save-<translate><!--T:78-->
 +
en</translate>.png|border]]
 +
<translate><!--T:79-->
 +
# Go to the frontend of your site and your menu should look similar to this. In the Protostar Template, the sublevel menu items are displayed as dropdown menu items.</translate>{{-}}[[Image:J3x-Create-Sublevel-Menu-Frontend-Sample-Dropdown-<translate><!--T:80-->
 +
en</translate>.png|775px|border]]
 +
<translate><!--T:81-->
 +
# The source code generated will look similar to this:</translate>
 +
<syntaxhighlight lang="html">
 +
<ul class="nav menu navbar-nav nav-pills">
 +
  <li class="item-101 current active"><a href="/" >Home</a></li>
 +
  <li class="item-102"><a class="dropdown-toggle" href="/about-us" >About Us</a></li>
 +
  <li class="item-210 deeper parent"><a href="#" >Dogs</a>
 +
    <ul class="nav-child unstyled small">
 +
      <li class="item-212"><a href="/2015-11-24-14-19-31/collies" >Collies</a></li>
 +
      <li class="item-213"><a href="/2015-11-24-14-19-31/pomeranians" >Pomeranians</a></li>
 +
    </ul>
 +
  </li>
 +
  <li class="item-211 deeper parent"><a href="#" >Cats</a>
 +
    <ul class="nav-child unstyled small">
 +
      <li class="item-214"><a href="/2015-11-24-14-20-12/burmese" >Burmese </a></li>
 +
      <li class="item-215"><a href="/2015-11-24-14-20-12/russian-blues" >Russian Blues</a></li>
 +
    </ul>
 +
  </li>
 +
</ul>
 +
</syntaxhighlight>
  
5. Select the "Collies" article for this example. {{-}}
+
<translate>
[[Image:J3x-Create-Sublevel-Menu-Menu-Item-Single-Article-en.png]]
+
===Example 2 - A Second Menu Module With Child Level Menu Items=== <!--T:82-->
 +
</translate>
  
6. On returning to the Article Detail page, fill in the Menu Item Title. Then click on the '''Parent Item''' select list located in the far right column. Find and select the "Dogs" parent item by scrolling through the Parent Item List. Note that menu levels are displayed with dashes: "-" (single dash) is the highest level, "--" (two dashes) is the second level, "---" third level and so on. {{-}}
+
<translate><!--T:83-->
[[Image:J3x-Create-Sublevel-Menu-Select-Parent-Item-en.png]]
+
To show in a separate module in a different position, follow these steps:</translate>
 +
<translate><!--T:84-->
 +
# Navigate to {{rarr|Extensions,Module Manager}} and locate or create a second Menu Module associated with your menu. For instructions on creating a new menu module, see</translate> <translate><!--T:85-->
 +
[[S:MyLanguage/Help34:Extensions Module Manager Menu|Module Menu]]</translate>{{-}}[[Image:J3x-Create-Sublevel-Menu-Module-Control-Panel-<translate><!--T:86-->
 +
en</translate>.png|775px|border]]
 +
<translate><!--T:87-->
 +
# Click on the module name associated with your menu. In this tutorial, we are selecting ''Left Menu''. Note: this image has been filtered by selecting ''Menu'' in the Module type dropdown.</translate>{{-}}[[Image:J3x-Create-Sublevel-Menu-Module-List-Menus-2-<translate><!--T:88-->
 +
en</translate>.png|775px|border]]
 +
<translate><!--T:89-->
 +
# In the Module details, set the ''Start level'' to ''2'', the ''End Level'' to ''All'' and set ''Show Submenu Items'' to ''Yes''. Note the position has changed and the menu we are pointing to is the ''Main Menu''.</translate>{{-}}[[Image:J3x-Create-Sublevel-Menu-Module-Details-2-<translate><!--T:90-->
 +
en</translate>.png|775px|border]]
 +
<translate><!--T:91-->
 +
# For this tutorial, we have used the ''Menu Assignment'' tab and assigned this Menu Module to appear on all pages except the home page.</translate>{{-}}[[Image:J3x-Create-Sublevel-Menu-Module-Module-Assignment-Tab-<translate><!--T:92-->
 +
en</translate>.png]]
 +
<translate><!--T:93-->
 +
# Click on ''Save & Close''.</translate>{{-}}[[Image:J3x-Create-Sublevel-Menu-Module-Save-<translate><!--T:94-->
 +
en</translate>.png]]
 +
<translate><!--T:95-->
 +
# Go to the frontend of your site and navigate to the ''Collies'' article. Your menu should look similar to this. Notice the child level subitems are the only items showing.</translate>{{-}}[[Image:J3x-Create-Sublevel-Menu-Frontend-Sample-Child-Menu-<translate><!--T:96-->
 +
en</translate>.png|775px|border]]
 +
<translate><!--T:97-->
 +
# The source code generated will look similar to this:</translate>
 +
<syntaxhighlight lang="html">
 +
<ul class="nav menu">
 +
  <li class="item-212 current active"><a href="/2015-11-24-14-19-31/collies" >Collies</a></li>
 +
  <li class="item-213"><a href="/2015-11-24-14-19-31/pomeranians" >Pomeranians</a></li>
 +
</ul>
 +
</syntaxhighlight>
  
7. Click on the button "Save and close" up in the top green buttons.
+
<translate>
{{-}}
+
==Sub-Sub-Menus== <!--T:98-->
[[Image:Joomla-3-Menu-Add-Menu-Save-en.png]] {{-}}
+
</translate>
8. Repeat steps 1-7 for the remaining articles "Pomeranians" with the "Dog" parent and articles "Burmese" and "Russian Blues" for the "Cat" parent. {{-}}
+
<translate><!--T:99-->
9.When you are finished with the "Menu Items" section, the Menu Item Manager should look very similar to the following:{{-}}[[Image:J3x-Create-Sublevel-Menu-Items-en.png|frame|center]]{{-}}
+
Using this same technique, it is easy to create third-level sub-menus. You just make the Parent Menu Item a second-level sub-menu. Then you could use the same technique to create a separate Menu Module with Start Level of 2 and End Level of 3. This would show only the third-level Menu Items.</translate>
 
 
==Step 4 - Setup the Menu Module==
 
At this point, we have our Articles and Menu Items done. Now we need to update the Menu Module. In Joomla!, the Menu Module determines three main things: a) what the menu looks like; b) where on the page it will show; and c) on which pages it will show. <br />We will do two examples. In the first example, we will set the parameters that show the parent level menu items with the lower level items beneath.
 
{{-}}
 
In the second example, we will add an additional menu module that appears in the left column and shows only the second level menu items. <br />
 
Note: We will do both examples using the Protostar Template included in the core Joomla! installation.
 
 
 
===Example 1 - One Menu Module With Second Level Items===
 
To show this as one module, follow these steps:
 
1. Navigate to '''Extensions &rarr; Module Manager''' and locate the Menu Module associated with your menu. If you need to create a new menu module, click here for instructions on creating a menu module: [[need link]] {{-}}
 
[[Image:J3x-Create-Sublevel-Menu-Module-Control-Panel-en.png]] {{-}}
 
2. Click on the module name associated with your menu. In this tutorial, we are selecting "Main Menu". Note: this image has been filtered by selecting "Menu" in the Module type dropdown.
 
[[Image:J3x-Create-Sublevel-Menu-Module-List-Menus-en.png.jpg]]
 
3.
 
<!-- # In the Menu Assignment, enter "Select Menu Item(s) from the List" and select "Home" (under "mainmenu"), and all of the Menu Items under the "Pets".  # Commented-out as it doesn't seem to exist in J3.2 -->
 
# In "Select Menu" select "Pets" from the drop-down list.
 
# If you are using the default "rhuk_milkyway" template and want the menu to look like the other menus, in the Advanced Parameters enter "_menu" for Module Class Suffix. 
 
# By the "Show Sub-menu Items" click on the "No" button. 
 
 
 
Now, navigate to the front-end home page or refresh/reload it. You should see the Pets Menu as shown below:[[Image:submenu_example3.png|frame|center]]Click on the Dogs Menu Item. The selected article displays and the Dogs menu expands to show the two submenu items, Collies and Greyhounds. Note that the default in "Show Sub-menu Items" was to always show sub-menu items.  We changed it to "show off". 
 
 
 
Click on "Collies" and again the article changes. (Or it would if we had different articles for each Menu Item!) The screen should look like the one below: [[Image:submenu_example4.png|frame|center]]
 
 
 
Notice that the Breadcrumbs now shows three levels: Home, Dogs, Collies. Because we used submenus, Joomla! "knows" that Collies is under Dogs.
 
 
 
===Separate Menu Modules===
 
Now we will change our example to create three separate menus -- one for the top level (Dogs and Cats), one for the Dogs (Collies and Greyhounds), and one for the Cats (Tabbies and Siamese).
 
 
 
<blockquote>''Note: Make sure that your Menu Items each have a unique Alias value. If you use the Copy command in the toolbar of the Menu Item Manager to create these Menu Items, the Alias will be the same as the item being copied. In this case, just edit the Alias value to make it unique (for example, the same as the Title). If you have duplicate Alias values, the menus will not work correctly if the parameter SEF URLs is set to Yes in Global Configuration.''</blockquote>
 
 
 
To do this:
 
# Open the Pets Menu in the Module Manager and change the Title from "Pets Menu" to "Pets Menu Top Level Only".
 
# Select the Left Top Position (position 7).
 
# Under the Module tab "Select Menu" drop-down to "Pets" or "Pets Menu"
 
# Set the Start Level to "1" and the End Level also to "1".
 
# ''This is optional. It allows your template to apply special a menu style to the menu (a border, for example).'' In Advanced Module Parameters put "_menu" in Module Class Suffix.
 
# For sub-menu "Dog", (in extensions menu select Module Manager (if you are not already there!)), click New and select Menu, and set the title to "Dogs Submenu".
 
# Set the Position to "Left top [position-7]".
 
# ''Now this part is very important.'' We only want this submenu to show when we are in one of the Dogs Menu Items. So, in the Menu Assignment box, select the three items "Dogs", "Collies", and "Greyhounds", as shown below: [[Image:submenu_example5.png|frame|center]]
 
# Under the "Module" tab, select the menu name "Pets Menu".
 
# Set the Start Level to "1" and End Level also to "1" again.  Try 2 for a spot of weirdness.
 
# ''This is optional.'' In Advanced Module Parameters, set Module Class Suffix to "_menu".
 
# For the "Cats Submenu", repeat steps from 7 to 12 except step 8. In the Menu Assignment box, select the items "Cat", "Tabbies" and "Siamese" (so this menu will only show under these Menu Items).
 
 
 
At this point, we have three menu modules all pointing to the Pets Menu. The only differences between them are (1) the Start and End Levels and (2) the Menu Item Assignment.
 
 
 
Now, in the front end, navigate to the Home page. The "Pets Menu Top Level Only" menu should show. Select the "Dogs" Menu Item. Now, the "Dogs Submenu" should show as a separate menu, as shown below:[[Image:submenu_example7.png|frame|center]]
 
 
 
Click on the Collies Menu Item and notice that again the Breadcrumbs shows the hierarchy of "Home", "Dogs", and "Collies".
 
 
 
==Sub-Sub-Menus==
 
Using this same technique, it is easy to create third-level sub-menus. You just make the Parent Menu Item a second-level sub-menu. Then you could use the same technique to create a separate Menu Module with Start Level of 2 and End Level of 3. This would show only the third-level Menu Items.
 
  
 +
<noinclude>
 +
<translate>
 +
<!--T:100-->
 +
[[Category:Beginners]]
 
[[Category:Tutorials]]
 
[[Category:Tutorials]]
 +
[[Category:Joomla! 3.x]]
 
[[Category:Menu Management]]
 
[[Category:Menu Management]]
 +
</translate>
 +
</noinclude>

Latest revision as of 13:39, 23 November 2022

Other languages:
Deutsch • ‎English • ‎Nederlands • ‎eesti • ‎español • ‎français • ‎italiano
Tutorial
How to Create a Submenu in a Joomla! Site
Joomla! 
3.x

In Joomla, submenus can be shown either as one menu with two or more levels or as completely separate menu modules. This is useful for constructing menus showing parent and child level navigation or for showing sublevel menu items in entirely separate positions on your template. To show how to do this, we will step through creating parent and child level menu items and then see how to show those items within one large menu and as a separate menu with only the child level items showing in a separate position on a template.

To begin, menus function with three basic constructs:

  • Articles - you need content to link to. This can also be component pieces, other menu items or external links.
  • Menu - describes the menu items, the type of navigation, their parent/child relationship to other menu items and the order they are displayed in.
  • Menu Module - controls the position and displaying of the menu.

For this tutorial, begin by logging into the Joomla Administrator. If you are unfamiliar with how to login see this article: Logging in or out of the Administrator backend.

Note For this tutorial you need Super Administrator permissions or permissions open enough to create and modify Articles, Menu Items, and Modules. For more information on User Access Control see ACL Tutorial.

Step 1 - Create Your Articles[edit]

In our example, we will create top level menu items for Dogs and Cats. Under Dogs, we will have Collies and Pomeranians. Under Cats we will have Burmese and Russian Blues. So the structure of our sample menu items will be as follows:

  • Dogs
    • Collies
    • Pomeranians
  • Cats
    • Burmese
    • Russian Blues

First, create 4 articles so our menu items will have something to link to: Collies, Pomeranians, Burmese and Russian Blue. See this tutorial if you need help creating an Article: Adding a new Article.

Step 2 - Create the Parent Level Menu Items[edit]

To create the structure, we need to navigate to the menu where we want our new menu items. If this is a new menu, you will need to create it. See this tutorial on how to create a menu: Adding a new menu.

Once you have your menu located in the Menu Manager, you will add the parent menu items using the System Links  External URL for each navigation link: Dogs and Cats.

Please note, there are other menu item types that can be used for the parent level navigation structure.

Here are the steps to create sample Menu Items using our example data. For more information on creating Menu Items see Adding a new menu item.

  1. Navigate to the Menu Manager by clicking on Menus  Menu Manager
    J3x-Edit-Main-Menu-en.jpg
  2. In the toolbar, click on New
    J3x-Edit-Main-Menu-Toolbar-new-en.png
  3. For the purposes of this exercise we are creating "placeholder" links using the System  External URL menu type for the Dogs and Cats parent level menu items. So, in the new Menu Item, click on the Menu Type select button:
    J3x-Add-Main-Menu-Select-Type-en.png
  4. Click on System Links then scroll down and select External URL.
    J3x-Create-Sublevel-Menu-System-External-Url-en.png
  5. Add the Menu Item Title ("Dogs") and type in a hashtag "#" in the Link box.
    J3x-Create-Sublevel-Menu-Menu-Item-External-Url-en.png
  6. Save your menu item.
    Joomla-3-Menu-Add-Menu-Save-en.png
  7. Repeat steps 2 - 6 for the Cats Parent Level menu item.

Step 3 - Create the Sublevel Menu Items[edit]

Now you will add the sublevel menu items using the Articles  Single Article to create menu links to the individual pages Collies, Pomeranians, Burmese, and Russian Blues. For each Menu Item created, we will set the Parentage to Dogs or Cats.

For more detailed information on how to create a Single Article Menu Type, see Adding a menu item which points to an Article.

Note There are other menu item types that can be used for the sublevel navigation structure.

  1. In the toolbar, click on "New".
    J3x-Edit-Main-Menu-Toolbar-new-en.png
  2. In the new Menu Item click on the Menu Type select button:
    J3x-Add-Main-Menu-Select-Type-en.png
  3. Select Articles  Single Article from the list displayed.
    J3x-Add-Main-Menu-Article-Type-en.png
  4. Returning to the Menu Item Detail page, click on the Select Article List.
    J3x-Add-Main-Menu-Article-Select-Article-en.png
  5. Select the Collies article for this example.
    J3x-Create-Sublevel-Menu-Menu-Item-Single-Article-en.png
  6. On returning to the Article Detail page, fill in the Menu Item Title. Then click on the Parent Item select list located in the far right column. Find and select the Dogs parent item by scrolling through the Parent Item List. Note that menu levels are displayed with hyphens: "-" (single hyphen) is the highest level, "--" (two hyphens) is the second level, "---" third level and so on.
    J3x-Create-Sublevel-Menu-Select-Parent-Item-en.png
  7. Click on the button Save & Close up in the top button.
    Joomla-3-Menu-Add-Menu-Save-en.png
  8. Repeat steps 1-7 for the remaining articles Pomeranians with the Dog parent and articles Burmese and Russian Blues for the Cat parent.
  9. When you are finished with the "Menu Items" section, the Menu Item Manager should look very similar to the following:
    J3x-Create-Sublevel-Menu-Items-en.png

Step 4 - Setup the Menu Module[edit]

At this point, we have our Articles and Menu Items done. Now we need to update the Menu Module. In Joomla!, the Menu Module determines three things:

  1. What the menu looks like.
  2. Where on the page it will show.
  3. Which pages it will show on.

We will do two examples:

  • In the first example, we will set the parameters that show the parent level menu items with the lower level items beneath.
  • In the second example, we will add an additional menu module that appears in the left column and shows only the second level menu items.

Note We will do both examples using the Protostar Template included in the core Joomla! installation.

Example 1 - One Menu Module With Second Level Menu Items[edit]

To show this as one module, follow these steps:

  1. Navigate to Extensions  Module Manager and locate the Menu Module associated with your menu. For instructions on creating a new menu module, see Module Menu
    J3x-Create-Sublevel-Menu-Module-Control-Panel-en.png
  2. Click on the module name associated with your menu. In this tutorial, we are selecting Main Menu. Note: this image has been filtered by selecting Menu in the Module type dropdown.
    J3x-Create-Sublevel-Menu-Module-List-Menus-en.png
  3. In the Module details, set the Start level to 1, the End Level to All and set Show Submenu Items to Yes.
    J3x-Create-Sublevel-Menu-Module-Details-en.png
  4. For this tutorial, we have added some styling in the Advanced tab. In the Menu Class Suffix we have entered navbar-nav nav-pills. You can also add navbar-nav nav-tabs for a slightly different look. Note: there is a space before navbar-nav.
    J3x-Create-Sublevel-Menu-Module-Advanced-Menu-Class-Suffix-en.png
  5. Click on Save & Close.
    J3x-Create-Sublevel-Menu-Module-Save-en.png
  6. Go to the frontend of your site and your menu should look similar to this. In the Protostar Template, the sublevel menu items are displayed as dropdown menu items.
    J3x-Create-Sublevel-Menu-Frontend-Sample-Dropdown-en.png
  7. The source code generated will look similar to this:
<ul class="nav menu navbar-nav nav-pills">
  <li class="item-101 current active"><a href="/" >Home</a></li>
  <li class="item-102"><a class="dropdown-toggle" href="/about-us" >About Us</a></li>
  <li class="item-210 deeper parent"><a href="#" >Dogs</a>
    <ul class="nav-child unstyled small">
      <li class="item-212"><a href="/2015-11-24-14-19-31/collies" >Collies</a></li>
      <li class="item-213"><a href="/2015-11-24-14-19-31/pomeranians" >Pomeranians</a></li>
    </ul>
  </li>
  <li class="item-211 deeper parent"><a href="#" >Cats</a>
    <ul class="nav-child unstyled small">
      <li class="item-214"><a href="/2015-11-24-14-20-12/burmese" >Burmese </a></li>
      <li class="item-215"><a href="/2015-11-24-14-20-12/russian-blues" >Russian Blues</a></li>
    </ul>
  </li>
</ul>

Example 2 - A Second Menu Module With Child Level Menu Items[edit]

To show in a separate module in a different position, follow these steps:

  1. Navigate to Extensions  Module Manager and locate or create a second Menu Module associated with your menu. For instructions on creating a new menu module, see Module Menu
    J3x-Create-Sublevel-Menu-Module-Control-Panel-en.png
  2. Click on the module name associated with your menu. In this tutorial, we are selecting Left Menu. Note: this image has been filtered by selecting Menu in the Module type dropdown.
    J3x-Create-Sublevel-Menu-Module-List-Menus-2-en.png
  3. In the Module details, set the Start level to 2, the End Level to All and set Show Submenu Items to Yes. Note the position has changed and the menu we are pointing to is the Main Menu.
    J3x-Create-Sublevel-Menu-Module-Details-2-en.png
  4. For this tutorial, we have used the Menu Assignment tab and assigned this Menu Module to appear on all pages except the home page.
    J3x-Create-Sublevel-Menu-Module-Module-Assignment-Tab-en.png
  5. Click on Save & Close.
    J3x-Create-Sublevel-Menu-Module-Save-en.png
  6. Go to the frontend of your site and navigate to the Collies article. Your menu should look similar to this. Notice the child level subitems are the only items showing.
    J3x-Create-Sublevel-Menu-Frontend-Sample-Child-Menu-en.png
  7. The source code generated will look similar to this:
<ul class="nav menu">
  <li class="item-212 current active"><a href="/2015-11-24-14-19-31/collies" >Collies</a></li>
  <li class="item-213"><a href="/2015-11-24-14-19-31/pomeranians" >Pomeranians</a></li>
</ul>

Sub-Sub-Menus[edit]

Using this same technique, it is easy to create third-level sub-menus. You just make the Parent Menu Item a second-level sub-menu. Then you could use the same technique to create a separate Menu Module with Start Level of 2 and End Level of 3. This would show only the third-level Menu Items.