Skip to content

Instantly share code, notes, and snippets.

@hagatorn
Last active December 17, 2015 04:58
Show Gist options
  • Save hagatorn/5554164 to your computer and use it in GitHub Desktop.
Save hagatorn/5554164 to your computer and use it in GitHub Desktop.
Recursive tree style accordion for kirby
<?php if(!isset($subpages)) $subpages = $site->pages();
if(!isset($id)) $id = 0; ?>
<?php $id+=1;
foreach($site->breadcrumb() AS $crumb):
$breadcrumb[] = $crumb->url();
endforeach ?>
<ul id="accordiongroup_<?php
$in = 0;
echo $id ?>" class="collapse <?php if ($id==1) {$in=1;}?>
<?php
foreach ($subpages->visible() AS $sp):
if(in_array($sp->url(), $breadcrumb)) {$in=1;}
endforeach;
if ($in==1) {echo 'in';}
?>
">
<?php
foreach($subpages->visible() AS $p): ?>
<?php if($p->hasChildren()){?>
<li class="depth-<?php echo $p->depth() ?> parent">
<a href="#accordiongroup_<?php echo $id+1 ?>" data-toggle="collapse" data-parent="<?php echo $id ?>"> <?php echo $p->title() ?></a>
<?php snippet('accordionmenu', array('subpages' => $p->children(), 'id' => $id)) ?>
<?php $id+=1;}
else { ?>
<li class="depth-<?php echo $p->depth() ?>">
<div><a class=" <?php echo ($p->isActive()) ? 'active' : '' ?>" href="<?php echo $p->url() ?>"><?php echo $p->title() ?></a></div>
<?php }
?>
</li>
<?php endforeach;?>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment