From 854839492cf0672c239924bca363898662bf50e4 Mon Sep 17 00:00:00 2001 From: Carlo Operio Date: Sat, 20 Jan 2018 21:36:41 -0500 Subject: [PATCH] Added navwalker.php and readme. --- Readme.md | 22 +++++++++++++++++++ navwalker.php | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 Readme.md create mode 100644 navwalker.php diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..55a8202 --- /dev/null +++ b/Readme.md @@ -0,0 +1,22 @@ +1) Place navwalker.php in your WordPress theme folder /wp-content/your-theme/ + +2) To use Bulma-navwalker add these lines to your functions.php + +require_once('navwalker.php'); +register_nav_menus( array( + 'primary' => __( 'Primary Menu', 'missionfit' ), +) ); + +3) Then add this initializer in your header (either index.php, header.php, etc...) + wp_nav_menu( array( + 'theme_location' => 'primary', + 'depth' => 2, + 'container' => false, + // 'items_wrap' => 'div', + 'menu_class' => 'navbar-menu', + 'menu_id' => 'primary-menu', + 'after' => "", + 'walker' => new Navwalker()) + ); + +3) Congratulations you are now using Bulma! \ No newline at end of file diff --git a/navwalker.php b/navwalker.php new file mode 100644 index 0000000..983fd7d --- /dev/null +++ b/navwalker.php @@ -0,0 +1,61 @@ +"; + } + + public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { + + $liClasses = 'navbar-item '.$item->title; + + $hasChildren = $args->walker->has_children; + $liClasses .= $hasChildren? " has-dropdown is-hoverable": ""; + + if($hasChildren){ + $output .= "
"; + $output .= "\n".$item->title.""; + } + else { + $output .= "".$item->title; + } + + // Adds has_children class to the item so end_el can determine if the current element has children + if ( $hasChildren ) { + $item->classes[] = 'has_children'; + } + } + + public function end_el(&$output, $item, $depth = 0, $args = array(), $id = 0 ){ + + if(in_array("has_children", $item->classes)) { + + $output .= "
"; + } + $output .= ""; + } + + public function end_lvl (&$output, $depth = 0, $args = array()) { + + $output .= ""; + } + } +?> \ No newline at end of file