The usage of more than one menu was shown on basis of the example template introduced in the previous sections. This section explains the required set-up and provides some information of the variables used by the menu function show_menu().

Difference of multiple menus and multiple menu calls

The term multiple menus is used for menus which acts independent of each other. This term should not be mixed up with multiple menu calls, which can be used to display different variants of one single menu. The application of both variants is highlighted below.

Multiple menus (independent of each other)

One application of two different menus is shown in the example template introduced in the previous sections. The template uses two independent menus. The top menu covers the pages "Disclaimer" and "Contact" another menu is used for the main navigation shown in the left column. Multiple menus allow to assign pages to different menu groups. This way one do not take care about menu levels, PAGE_ID and so on.

Multiple menus require additional entries in the file info.php of your template. Apart from that the usage of multiple menus must be enabled in the WB Settings.

Multiple menu calls

It is possible to invoke the menu functions (show_menu, show_menu2) several times for one and the same menu. Multiple menu calls can be used to display all parent pages (root level) of one menu at one location, all pages from the second menu level onwards (root level +1 ) at another location. This method is e.g. used for the set-up of multilingual pages. Another examplte is to output a "You are here link trail" (breadcrumbs) by the use of the external code snippet show_menu2 beside the main navigation menu.

You can use multiple menu calls for one menu (first parameter of the menu function $menu_number is identical) by adding several menu calls to the index.php file of your template. This method does not required to add additional entries to the info.php or to change any WB settings.

Using multiple menus

Multiple menus can be used to group pages to a certain menu (e.g. "Disclaimer" and "Contact"). To use more than one independent menu (don´t mix up with multiple menu calls) requires the steps shown below.

Step 1: Modifying the template files

File: info.php
WebsiteBaker requires a unique name in the info.php file for each additional menu. This information is provided via the array variable $menu[x]. The main menu should be labeled as number 1, followed by the additional menus you want to add. An example with two independent menus is provided below. 

// definitions for multiple menues (required if more than one menu is used)
$menu[1]    = 'Main navigation';
$menu[2]    = 'Top navigation';

The menu names are shown in the WB backend to assign pages to a certain menu. Therefore one should use speaking names for the different menus.

File: index.php
Each individual menu requires a template function call in the index.php file of your template. The parameter passed over to the function show_menu(x) corresponds to the menu number assigned in the info.php file. Place the template function calls at the location in your template where the menu should be displayed.

<?php show_menu(1); ?>
<?php show_menu(2); ?>   

Step 2: Adapt the WB setting

Multiple menus are disabled per default in the WebsiteBaker default settings. The usage of multiple menus can be enabled via the WB backend: Settings -> Show Advanced Options -> Multible Menus -> Enabled

Step 3: Assign pages to different menus

If you add a new page via the WB backend, it will be assigned by default to the first menu $menu[1].
You can assign a page to another menu via the the WB backend: Pages -> Settings Page Settings

The following dialogue appears.

Assign a page to a menu

Figure 1: Assign a page to a menu

Via the dropdown menu "Menu:" shown in the figure above, one can assign a page to any menu defined in the info.php file of your template.

Variables of show_menu

Here is an overview of the Variables used in the menu function show_menu(), which is the standard menu function of WebsiteBaker since WB 2.6.x. It replaces the old page_menu() function of Website Baker 2.5.x.

Depending on the appliction, the menu function show_menu can be invoked several times from the index.php file of the template. A value greater than 1 for the first variable indicates the usage of multiple independent menus.

To just display the standard menu, use <?php show_menu(); ?> within your template's HTML code. You don't normally need anymore than the first four arguments.

Syntax (for usage in the template´s index.php file):

<?php show_menu($menu_number, $start_level, $recurse, $collapse, $item_template,
                $item_footer, $menu_header, $menu_footer, $default_class, 
                $current_class,$parent); ?>

 The Variables explained:

Position Variable Description Default Value
1 $menu_number With activitated "multiple menu" feature you can choose which menu will be displayed 1
2 $start_level The depth level of the root of the displayed menu tree. Defaults to '0', which is the top level. '1' will show all pages starting from the first sub level. 0
3 $recurse Gives the maximum number of levels to be displayed. Default is '-1' which means 'all'. -1
4 $collapse Specifies, whether the menu tree shall be expandable/collapsible (if set to 'true') or complete (all pages being displayed) if set to 'false' true
5 $item_template Gives the possibility to specify the html code that is displayed before displaying sub-pages '<li><span[class]>[a][menu_title] [/a]</span>'
6 $item_footer The html code to appear after sub-pages were displayed. '</li>'
7 $menu_header The html code to appear before the entire menu code and each sub tree. '<ul>'
8 $menu_footer The html code to appear after the entire menu code and each sub tree. '</ul>'
9 $default_class The (CSS) class of every menu item except the currently viewed page ' class="menu_default"'
10 $current_class The class of the currently viewed page ' class="menu_current"'
11 $parent (used internally) The page_id of the menu's root node, defaults is '0' (root level) 0

Examples

show_menu(1,0,-1,false); - displays the complete page tree expanded
show_menu(1,1,1); - show only first sub level
show_menu(1,1,-1); - show an expanding/collapsing menu tree starting at level 1

Note:

The WB function show_menu() creates invalid (X)HTML code if nested lists are used. If you need to create valid (X)HTML code, you should consider to use the external code snippet show_menu2 available from the Add-ons Repository.

Apart from valid (X)HTML code, show_menu2 is faster and contains a lot of features which allow to style each menu you could think of. Further information can be found in the Readme file and from the developers homepage .

X This website uses cookies. When you browse on this site, you agree to the use of cookies.