-
-
Save Narga/5149983 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Adding a Foundation Top Bar to WordPress | |
foundation-topbar-menu.php and foundation-topbar-walker.php should be included in the WordPress functions.php file. | |
The code in foundation-topbar.php should be added below the body tag in header.php | |
Setup a menu in WordPress admin under Appearance > Menus | |
Use the section class on a menu item to create a menu section title | |
Foundation Top Bar Doc: http://foundation.zurb.com/docs/components/top-bar.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Customize the output of menus for Foundation top bar classes | |
*/ | |
class top_bar_walker extends Walker_Nav_Menu { | |
function display_element($element, &$children_elements, $max_depth, $depth=0, $args, &$output) { | |
$element->has_children = !empty($children_elements[$element->ID]); | |
$element->classes[] = ($element->current || $element->current_item_ancestor) ? 'active' : ''; | |
$element->classes[] = ($element->has_children) ? 'has-dropdown' : ''; | |
parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output); | |
} | |
function start_el(&$output, $item, $depth, $args) { | |
$item_html = ''; | |
parent::start_el($item_html, $item, $depth, $args); | |
$output .= ($depth == 0) ? '<li class="divider"></li>' : ''; | |
$classes = empty($item->classes) ? array() : (array) $item->classes; | |
if(in_array('section', $classes)) { | |
$output .= '<li class="divider"></li>'; | |
$item_html = preg_replace('/<a[^>]*>(.*)<\/a>/iU', '<label>$1</label>', $item_html); | |
} | |
$output .= $item_html; | |
} | |
function start_lvl(&$output, $depth = 0, $args = array()) { | |
$output .= "\n<ul class=\"sub-menu dropdown\">\n"; | |
} | |
} // end top bar walker | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="top-bar-container fixed contain-to-grid"> | |
<nav class="top-bar"> | |
<ul class="title-area"> | |
<li class="name"> | |
<h1><a href="<?php echo home_url(); ?>"><?php bloginfo('name'); ?></a></h1> | |
</li> | |
<li class="toggle-topbar menu-icon"><a href="#"><span>Menu</span></a></li> | |
</ul> | |
<section class="top-bar-section"> | |
<?php foundation_top_bar_l(); ?> | |
<?php foundation_top_bar_r(); ?> | |
</section> | |
</nav> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment