Topic: submenu snippet

snippet:

<?php
    function snippet_submenu() {
        
        // get the current subpages
        $pages = Page::children(Pages::$requested_page);

        // try to get the parent
        if ( ! isset($pages)) {
            $current_page = Pages::$requested_page;
            $parent_page = '';
            if ($current_page !== 'error404') {
                $page = Pages::$pages->select('[slug="'.$current_page.'"]', null);
                
                // try again if we have a parent                
                if (trim($page['parent']) !== '') {
                    $parent_page = Pages::$pages->select('[slug="'.$page['parent'].'"]', null);
                    $pages = Pages::$pages->select('[parent="'.(string)$parent_page['slug'].'"]', 'all');
                }
            }
        }
        return $pages;
    }
    
    $sub_pages = snippet_submenu();
    if (isset($sub_pages)) {
?>
        <ul class="nav nav-pills">
<?php
        foreach($sub_pages as $page) {
            $li_class_active = '';
            if (Pages::$requested_page == $page['slug']) $li_class_active = ' class="active"';
?>
            <li<?php echo $li_class_active; ?>><a href="<?php echo Site::url() . $page['parent'] . '/' . $page['slug']; ?>"><?php echo $page['title']; ?></a></li>
<?php
        }
?>
        </ul>
<?php
    }
?>

usage:

{snippet get="submenu"}

http://antiben.an.funpic.de/pictures/monstra_navpills.png