Last active
November 27, 2017 01:02
-
-
Save vmasciotta/6355336 to your computer and use it in GitHub Desktop.
Foundation Zurb TopBar Navigation for Drupal
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
//add this in page.tpl.php | |
<?php if ($main_menu): ?> | |
<div class="row"> | |
<div class="twelve columns"> | |
<nav id="navigation" class="top-bar"> | |
<ul> | |
<li class="name"><h1><a href="#">Navigation</a></h1></li> | |
<li class="toggle-topbar"><a href="#"></a></li> | |
</ul> | |
<section class="section"> | |
<ul class="left"> | |
<?php print theme( | |
'links__system_main_menu', array('links' => $main_menu, | |
'attributes' => array('id' => 'main-menu', | |
'class' => array('links', | |
'inline', | |
'clearfix')), | |
'heading' => t('Main menu')) | |
); ?> | |
</ul> | |
</section> | |
</nav> | |
</div> | |
</div> | |
<?php endif; ?> | |
//add this function in template.php | |
function YOURTHEME_links__system_main_menu($vars) | |
{ | |
// Get all the main menu links | |
$menu_links = menu_tree_output(menu_tree_all_data('main-menu')); | |
// Initialize some variables to prevent errors | |
$output = ''; | |
$sub_menu = ''; | |
foreach ($menu_links as $key => $link) { | |
// Add special class needed for Foundation dropdown menu to work | |
!empty($link['#below']) ? $link['#attributes']['class'][] = 'has-dropdown' : ''; | |
// Render top level and make sure we have an actual link | |
if (!empty($link['#href'])) { | |
$output .= '<li' . drupal_attributes($link['#attributes']) . '>' . l($link['#title'], $link['#href']); | |
// Get sub navigation links if they exist | |
foreach ($link['#below'] as $key => $sub_link) { | |
if (!empty($sub_link['#href'])) { | |
$sub_menu .= '<li>' . l($sub_link['#title'], $sub_link['#href']) . '</li>'; | |
} | |
} | |
$output .= !empty($link['#below']) ? '<ul class="dropdown">' . $sub_menu . '</ul>' : ''; | |
// Reset dropdown to prevent duplicates | |
unset($sub_menu); | |
$sub_menu = ''; | |
$output .= '</li>'; | |
} | |
} | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What's version of drupal and foundation do you use?