Mastering the Menu - Article #2
This is the second article in a series of articles on the printMenu() method.
This time around we are going to look into how a template can specify what pages should be included in a menu listing. This can be used to create a site map, a fully collapsed menu usable for the fancy bling-bling drop-down menus, or create a special menu displaying a sub-tree of the menu.
Example 1 - Expanding the menu
By sending "expand" as the show parameter, it is possible to expand all visible pages in the menu. This can be used for a number of CSS or JavaScript based drop-down menus, that require access to the complete menu tree, or a simple site map.
Below is an example where the menu is expanded, and a CSS/JavaScript drop-down menu applied to the div containing the menu tree. The example below requires the CSS and Javascript files from the Drop-Down Menus, Horizontal Style article on alistapart.com
<html>
<head>
<script type="text/javascript" src="drop_down.js"></script>
<style type="text/css">
@import "style2.css";
</style>
</head>
<body>
<div id="nav">
<?php $parser->printMenu("", "expand"); ?>
</div>
<div id="content">
<?php $parser->printSiteContent(); ?>
</div>
</body>
</html>
A quick copy/paste version of the A List Apart article menu filled with menu items from the fundausers.org menu can be seen at http://fundausers.org/article scripts/masteringthemenu/showexpand.php. The menu clearly contains some layout bugs due to the CSS not coping with the long page titles.
Example 2 - Listing specific pages
The show parameter can be used to include only a limited set of pages in the menu. By giving comma separated string of page IDs, or an array of page IDs the printMenu method will automatically make sure that these pages are included in the menu.
The two example menu calls below are equivalent, since the first is converted to the array used in the second.
<?php
$parser->printMenu("", "1,5,6");
$parser->printMenu("", array(1, 5, 6));
?>
Example 3 - An empty argument
If no argument is given, the show parameter defaults to the ID of the current page - equivalent to sending $parser->ID as the argument. This ensures that the current page is always visible in the menu.
Summary
This article has given a quick introduction to how the show parameter of the printMenu method can be used to control what menu items are displayed in the menu.
Article Series
#1 Introduction to printMenu - arrMS parameter
This article gives an introduction to the printMenu method and describe the different menu item templates and how they can be styled.
#2 Show parameter
This article gives examples on how the show parameter can be used to expand sub-menus.
#3 Style parameter
This article describe how the style parameter can be used to control how the printMenu method acts, e.g. if it should use non-breaking spaces and maximum number of menu item levels to print.
#4 Mode parameter
This article explain how to use the mode parameter to control if the printMenu method should include hidden pages.
