Trace: » use_helper » pager » pagination » comments » setup_archive_pages » howto » accesskey » collapsing » inline-horizontal » leave-out
Translations of this page?:
General
Getting & Giving Support
Administration
Design
- Tut. - Layouts and Themes
- Tut. - Navigation cookbook
- Tut. - How To section
Reference Material
Plugin Development
- Tut. - Writing a plugin
- Ref. - List of Events
- Ref. - Enabling cron jobs
- Ref. - PHPDoc
Core Development
- Ref. - PHPDoc
Press information
Wolf CMS books section
Omitting Pages from Navigation
Here's a simple way to omit certain pages out of your navigation menu:
<ul> <li<?php echo url_match('/') ? ' id="current"': null; ?>><a href="<?php echo URL_PUBLIC; ?>">Home</a></li> <?php foreach($this->find('/')->children() as $menu): ?> <?php $omit_pages = array('somepageslug', 'someotherpageslug'); if (in_array($menu->slug, $omit_pages)) { continue; } ?> <li<?php echo (url_start_with($menu->url)) ? ' id="current"': null; ?>> <?php echo $menu->link() . PHP_EOL; ?></li> <?php endforeach; ?> </ul>
Change the slug values in the $omit_pages array to match the slugs of the pages you want to omit from your navigation.
The same technique can be used with page id's instead, in this example pages 3, 6 and 9 are omitted:
<ul> <li<?php echo url_match('/') ? ' id="current"': null; ?>><a href="<?php echo URL_PUBLIC; ?>">Home</a></li> <?php foreach($this->find('/')->children() as $menu): ?> <?php $omit_pages = array(3,6,9); if (in_array($menu->id, $omit_pages)) { continue; } ?> <li<?php echo (url_start_with($menu->url)) ? ' id="current"': null; ?>> <?php echo $menu->link() . PHP_EOL; ?></li> <?php endforeach; ?> </ul>
Here's a function that does all of the above:
<?php function snippet_sitemap($parent,$omit_pages=false) { $out = ''; $childs = $parent->children(); if (count($childs) > 0) { $out = '<ul class="sitemap">' . PHP_EOL; foreach ($childs as $child) { if($child->getLoginNeeded() == Page::LOGIN_REQUIRED) { continue; } if (in_array($child->id, $omit_pages)) { continue; } $out .= '<li>'.$child->link().snippet_sitemap($child).'</li>' . PHP_EOL; } $out.= '</ul>' . PHP_EOL; } return $out . PHP_EOL; } // can be used for sitemap, navigation and such // omit pages 3, 6 and 9 echo snippet_sitemap($this->find('/'),array(3,6,9)); ?>
Except where otherwise noted, content on this wiki is licensed under the following license:GNU Free Documentation License 1.2
