Skip to content

Instantly share code, notes, and snippets.

@cfxd
Created October 25, 2014 03:42
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cfxd/b46fe1428f5a354495f9 to your computer and use it in GitHub Desktop.
Save cfxd/b46fe1428f5a354495f9 to your computer and use it in GitHub Desktop.
Roots Navigation with FCF Fields. See http://cfxdesign.com/one-page-wordpress-theme-workflows
/*
*
* Assumes:
* 1. You have a FCF field called 'sections'
* 2. Each FCF block has a text sub field called 'section-title'
*
*/
<?php
global $post;
$id = $post->id;
$sections = get_field('sections', $id);
$home_slug = sanitize_title($sections[0]['section-title']);
?>
<header class="banner navbar navbar-default navbar-static-top" role="banner">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#<?php echo $home_slug; ?>"><?php bloginfo('name'); ?></a>
</div>
<?php if(have_rows('sections')) : ?>
<nav class="collapse navbar-collapse" role="navigation">
<ul class="nav navbar-nav">
<?php while(have_rows('sections')) : ?>
<?php the_row(); ?>
<li class="menu-<?php echo sanitize_title(get_sub_field('section-title')); ?>"><a href="#<?php echo sanitize_title(get_sub_field('section-title')); ?>"><?php echo get_sub_field('section-title'); ?></a></li>
<?php endwhile; ?>
</ul>
</nav>
<?php endif; ?>
</div>
</header>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment