Skip to content

Instantly share code, notes, and snippets.

@bigtreecms
Last active December 15, 2015 04:59
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 bigtreecms/5205661 to your computer and use it in GitHub Desktop.
Save bigtreecms/5205661 to your computer and use it in GitHub Desktop.
Basic subnavigation loop.
<?
/*
Basic subnavigation loop.
-Draws 2 levels at a time
-Ignores top level (never re-draws main navigation)
-If page has children, draws page's siblings and subs
-If no children, draws parent's and page's siblings.
*/
$currentURL = BigTree::currentURL();
$parent = $cms->getPage($page["parent"]);
$top = ($parent["parent"] < 1) ? (($parent["id"] == 0) ? $page["id"] : $parent["id"]) : $parent["parent"];
$subnav = $cms->getNavByParent($top, 2);
if (!$is404) {
?>
<nav class="subnavigation">
<?
foreach ($subnav as $item) {
$isActive = $currentURL == $item["link"];
$isOpen = (strpos($currentURL, $item["link"]) > -1);
$hasChildren = (count($item["children"]) > 0);
?>
<div class="item<? if ($isActive || $isOpen) echo ' active'; ?>">
<a href="<?=$item["link"]?>" class="<? if ($isOpen) echo ' open'; ?><? if ($isActive) echo ' active'; ?><? if ($hasChildren && $isOpen) echo ' parent'; ?>"><?=$item["title"]?></a>
<? if ($hasChildren && $isOpen) { ?>
<div class="children">
<?
foreach ($item["children"] as $child) {
$isActiveChild = (strpos($currentURL, $child["link"]) > -1);
?>
<a href="<?=$child["link"]?>" class="child<? if ($isActiveChild) echo ' active'; ?>"><?=$child["title"]?></a>
<?
}
?>
</div>
<? } ?>
</div>
<?
}
?>
</nav>
<?
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment