Documentation

Light-weight, fast, simple and powerful!
 
Translations of this page?:

Recipe: Sitemap-like navigation for Sub-areas

You may wish to have sidebar navigation to the pages for each “main” or “top” page (i.e., child-of-homepage) in your site. This system “automates” such menus, no matter how many “top” pages you have or delete, and no matter how deep the navigation is below them. Here's how:

1. Make this snippet; call it, e.g., sitemap_nav:

<?php
function nav_sitemap($parent)
{
    $out = '';
    $childs = $parent->children();
    if (count($childs) > 0)
    {
        $out = '<ul>';
        foreach ($childs as $child)
            $out .= '<li>'.$child->link().nav_sitemap($child).'</li>';
        $out.= '</ul>';
    }
    return $out;
}
?>
<?php $topSlug = explode('/', $_SERVER['REQUEST_URI']); $areaSlug = $topSlug[1] ?>
 
<div id="sitemap_nav">
<?php if ($areaSlug == 'sitemap' || $areaSlug == '') {
  // put what to do if on Homepage or Sitemap here; current default is to do nothing
} else {
  echo '<p><strong><a href="'. URL_PUBLIC .'" title="Home" >Home Menu</a></strong></p>';
  echo '<p><strong>'.$this->find($areaSlug)->link().'</strong></p>'; // = Top of sub-area
  echo nav_sitemap($this->find($areaSlug)); } 
?>
</div>

2. In your Layout, add the following code in your sidebar <DIV>:

<!-- start sitemap nav -->
<?php $this->includeSnippet('sitemap_nav'); ?>
<!-- end sitemap nav -->

(You can omit the comment lines, of course!) And that's it.

Notes

  1. By default, this code puts nothing on your homepage or sitemap page (if you have one; and if you do, this code will not break your sitemap page).
  2. If your Wolf site is in a subdirectory (e.g. www.example.com/wolf/), then change $topSlug[1] to $topSlug[2] .
  3. It is possible that not using mod_rewrite (thus leaving a ”?” in the URL), or using a URL suffix (e.g., .html), will throw off the search for the slug!
  4. The code is a bit more verbose than it needs to be; this is to keep the layout choices a little more clear. Alter these to suit your own preferences. In particular, you might want to remove the “Home Menu” line, i.e., next line after } else {
  5. This is somewhat like mvdkleijn's “Unlimited levels and children” system (above), but it lacks the control that his system gives you over certain aspects of the navigation.
 
navbook/sitemap-style.txt · Last modified: 2011-09-12 00:46 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license:GNU Free Documentation License 1.2
Copyright 2010 wolfcms.org / design by yello studio / Wolf CMS Inside