Skip to content

Instantly share code, notes, and snippets.

@Awilum
Last active December 20, 2018 16:12
Show Gist options
  • Save Awilum/17eb8faad539528f004cf1c7beea84b2 to your computer and use it in GitHub Desktop.
Save Awilum/17eb8faad539528f004cf1c7beea84b2 to your computer and use it in GitHub Desktop.
Flextype: Navigation based on published pages
// Sort pages by pages slug
<ul class="navbar-nav">
<?php $pages = Content::getPages('', false, 'slug'); ?>
<?php foreach ($pages as $page) { ?>
<?php if ($page['slug'] !== '404' && !(isset($page['visibility']) && ($page['visibility'] === 'draft' || $page['visibility'] === 'hidden'))) { ?>
<li class="nav-item">
<a class="nav-link <?php if (Http::getUriString() == $page['slug']) echo 'active'; ?>" href="<?php echo Http::getBaseUrl().'/'.$page['slug']; ?>"><?php echo $page['title']; ?></a>
</li>
<?php } } ?>
</ul>
// Sort pages by pages menu-order field
<ul class="navbar-nav">
<?php $pages = Content::getPages('', false, 'menu-order'); ?>
<?php foreach ($pages as $page) { ?>
<?php if ($page['slug'] !== '404' && !(isset($page['visibility']) && ($page['visibility'] === 'draft' || $page['visibility'] === 'hidden'))) { ?>
<li class="nav-item">
<a class="nav-link <?php if (Http::getUriString() == $page['slug']) echo 'active'; ?>" href="<?php echo Http::getBaseUrl().'/'.$page['slug']; ?>"><?php echo $page['title']; ?></a>
</li>
<?php } } ?>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment