A Simple Navigation
Currently, our navigation is rather static:
<a href="<?php echo url('about'); ?>">About</a> <a href="<?php echo url('contact'); ?>">Contact</a>
Should we decide to add a page or change one of the existing pages' URL or title, we'd have to change the navigation, too. For such a small project like our blog, this approach is definitely acceptable. However, we're pros - so let's do it in a professional manner.
Remember that we created the "about" and "contact" page folders with preceding numbers? By doing this, we automatically marked these pages as "visible" and assigned them a sorting order. For creating a navigation, both is convenient:
<?php foreach($pages->visible() as $mainpage): ?> <a href="<?php echo $mainpage->url(); ?>"> <?php echo $mainpage->title(); ?> </a> <?php endforeach; ?>
With $pages->visible(), we get a collection of all visible (i.e. numbered) pages on the root level. Transforming this into a "navigation" is then only a matter of cycling through these items and outputting each page's URL and title in a link.