-
-
Save zslabs/4319430 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
This code should be added to the WordPress functions.php file. | |
Call the menu in your theme by using <?php foundation_nav_bar(); ?> | |
Setup a menu in WordPress admin under Appearance > Menus | |
Note: the function main_nav_fb() could be used to echo an error instead of wp_list_pages as a menu. If you choose to not use wp_list_pages the page_walker is not needed. |
This file contains hidden or 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 page list for Foundation nav classes in main_nav_fb | |
http://forrst.com/posts/Using_Short_Page_Titles_for_wp_list_pages_Wordp-uV9 | |
*/ | |
class page_walker extends Walker_Page { | |
function start_el(&$output, $page, $depth, $args, $current_page) { | |
$indent = ($depth) ? str_repeat("\t", $depth) : ''; | |
extract($args, EXTR_SKIP); | |
$classes = array('page_item', 'page-item-'.$page->ID); | |
if (!empty($current_page)) { | |
$_current_page = get_page( $current_page ); | |
if (isset($_current_page->ancestors) && in_array($page->ID, (array) $_current_page->ancestors) ) | |
$classes[] = 'current_page_ancestor'; | |
if ($page->ID == $current_page) | |
$classes[] = 'current_page_item active'; | |
elseif ($_current_page && $page->ID == $_current_page->post_parent) | |
$classes[] = 'current_page_parent'; | |
} elseif ($page->ID == get_option('page_for_posts') ) { | |
$classes[] = 'current_page_parent'; | |
} | |
if (get_children($page->ID)) | |
$classes[] = 'has-flyout'; | |
$classes = implode(' ', apply_filters('page_css_class', $classes, $page)); | |
$output .= $indent.'<li class="'.$classes.'">'; | |
$output .= '<a href="'.get_page_link($page->ID).'" title="'.esc_attr(wp_strip_all_tags($page->post_title)).'">'; | |
$output .= $args['link_before'].$page->post_title.$args['link_after']; | |
$output .= '</a>'; | |
} | |
function end_el(&$output, $item, $depth) { | |
$output .= "</li>\n"; | |
} | |
function start_lvl(&$output, $depth) { | |
$indent = str_repeat("\t", $depth); | |
$output .= "\n$indent<ul class=\"sub-menu flyout\">\n"; | |
} | |
function end_lvl(&$output, $depth) { | |
$indent = str_repeat("\t", $depth); | |
$output .= "\n$indent</ul>\n"; | |
} | |
} // end page walker | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added-in check for top-level ancestors (so they can get the 'active' class as well for proper menu highlighting