Skip to content

Instantly share code, notes, and snippets.

@angrycat
Created June 19, 2012 11:15
Show Gist options
  • Save angrycat/2953583 to your computer and use it in GitHub Desktop.
Save angrycat/2953583 to your computer and use it in GitHub Desktop.
ProcessWire Build tree for navigation
<?php
define("n","\n");
define("br","<br />");
function buildTopMenu($pages, &$depth, $selector='', $maxDepth=2) {
global $active;
$out = '';
if($depth <= $maxDepth && $pages->getTotal() > 0) {
$depth++;
$out .= "<ul class='depth-{$depth}'>".n;
foreach($pages as $p) {
$css = '';
if($active == $p->id) {$css = ' class="active"';}
$out .= "<li{$css}><a href='{$p->url}' data-id='{$p->id}'>{$p->title}</a>".n;
$out .= buildTopMenu( $p->children($selector), $depth, $selector, $maxDepth );
$out .= "</li>".n;
}
$depth--;
$out .= "</ul>".n;
}
return $out;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment