Skip to content

Instantly share code, notes, and snippets.

@BinaryKitten
Created August 8, 2013 13:03
Show Gist options
  • Select an option

  • Save BinaryKitten/6184385 to your computer and use it in GitHub Desktop.

Select an option

Save BinaryKitten/6184385 to your computer and use it in GitHub Desktop.
<?php
class Pico_Cascadenav
{
public function get_pages(&$pages, &$current_page, &$prev_page, &$next_page)
{
$newPages = array('pages' => array());
foreach($pages as $page) {
$path = parse_url($page['url'], PHP_URL_PATH);
$crumbs_main = explode("/", $path);
$crumbs = array_filter($crumbs_main);
if (count($crumbs) == 0) {
$newPages = array_merge($newPages, $page);
// if we have no subparts then skip ahead usually this is for /
continue;
}
$key = array_pop($crumbs);
$current = $item = array('pages' => array($key => $page + array('pages' => array())));
while(count($crumbs) > 0) {
$key = array_pop($crumbs);
$current = array('pages' => array($key => $current));
$item = array_merge($item, $current);
}
echo '<hr/>';
$newPages = array_merge($newPages, $item);
}
// die();
$pages = array($newPages);
// echo '<pre>'; var_dump($pages);
// die();
}
}
<ul class="nav">
{% include "menu.html" with {'pages':pages} only %}
</ul>
{% for page in pages %}
<li>
<a href="{{ page.url }}">{{ page.title }}</a>
{% if page.pages %}
<ul>
{% include "menu.html" with {'pages': page.pages} %}
</ul>
{% endif %}
</li>
{% endfor %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment