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; ?>

Code on GitHub

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.

Giveaways. Cheat Sheets. eBooks. Discounts.
And great content from our blog!

About Us

As the makers of Tower, the best Git client for Mac and Windows, we help over 100,000 users in companies like Apple, Google, Amazon, Twitter, and Ebay get the most out of Git.

Just like with Tower, our mission with this platform is to help people become better professionals.

That's why we provide our guides, videos, and cheat sheets (about version control with Git and lots of other topics) for free.