Skip to content

Instantly share code, notes, and snippets.

@ezeey
Created March 21, 2013 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ezeey/5216516 to your computer and use it in GitHub Desktop.
Save ezeey/5216516 to your computer and use it in GitHub Desktop.
Example of how to add children to the homepage in ProcessWire in combination with the MarkupSimpleNavigation module. See: http://processwire.com/talk/topic/3065-direct-children-of-default-front-page/.
<?php
// Get the homepage
$homepage = $pages->get("/");
// Get all the homepage children who need to be under home in the menu
$homePageChildren = $homepage->children("homechild=1");
// Store this in a variable so you can output it later
$homeMenu = "<ul>";
// Loop through the homepage children and store them in the var
foreach($homePageChildren as $homePageChild) {
$homeMenu .= "<li><a href='{$homePageChild->url}'>{$homePageChild->title}</a></li>";
}
$homeMenu .= "</ul>";
// Start the actual menu here
echo "<ul>";
// Create the link to home and output the $homeMenu
echo "<li><a href='{$homepage->url}'>{$homepage->title}</a>{$homeMenu}</li>";
// Start Markup Simple Navigation
$options = array(
'parent_class' => 'parent', // string (default 'parent') overwrite class name for current parent levels
'current_class' => 'current', // string (default 'current') overwrite current class
'has_children_class' => 'has_children', // string (default 'has_children') overwrite class name for entries with children
'levels' => false, // bool (default false) wether to output "level-1, level-2, ..." as css class in links
'levels_prefix' => 'level-', // bool (default 'level-') prefix string that will be used for level class
'max_levels' => 3, // int (default null) set the max level rendered
'firstlast' => true, // bool (default false) puts last,first class to link items
'collapsed' => false, // bool (default false) if you want to auto-collapse the tree you set this to true
'show_root' => false, // bool (default false) set this to true if you want to rootPage to get prepended to the menu
'selector' => 'homechild=0', // string (default '') define custom PW selector, you may sanitize values from user input
'outer_tpl' => '', // template string for the outer most wrapper. || will contain entries
'inner_tpl' => '<ul>||</ul>', // template string for inner wrappers. || will contain entries
'list_tpl' => '<li%s>||</li>', // template string for the items. || will contain entries, %s will replaced with class="..." string
'item_tpl' => '<a href="{url}">{title}</a>', // template string for the inner items. Use {anyfield} and {url}, i.e. {headline|title}, if field is of type image it will return url to image (first image if multiple)
'item_current_tpl' => '<a href="{url}">{title}</a>' // template string for the active inner items.
);
// Output Markup Simple Navigation
echo $treeMenu->render($options);
echo "</ul>";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment