using separate nav menus instead of one topbar
authorAnthony Talarico <talarico@gaslightmedia.com>
Mon, 15 Jan 2018 20:55:20 +0000 (15:55 -0500)
committerAnthony Talarico <talarico@gaslightmedia.com>
Mon, 15 Jan 2018 20:55:20 +0000 (15:55 -0500)
changing the topbar to use separate nav menus

lib/navigation.php
sections/header.php

index 7f5eb6f..3f6cfb5 100644 (file)
@@ -1,41 +1,59 @@
 <?php
 
 register_nav_menus(array(
-  'top-bar'     => 'Site Navigation',
+  'boards'      => 'boards-committees',
+  'departments' => 'departments-services',
+  'township'    => 'township-resources',
+  'calendar'    => 'township-calendar',
   'mobile-menu' => 'Off Canvas',
   'alt-menu'    => "How Do I...",
-
 ));
-if ( ! function_exists( 'glm_theme_members_only' ) ) {
-    function glm_theme_members_only($location) {
-        echo '<ul class="members-only">';
-        echo glm_theme_top_bar( $location );
-        echo '</ul>';
-    }
-}
 
 /**
  * Top Bar
  */
 if ( ! function_exists( 'glm_theme_top_bar' ) ) {
-  function glm_theme_top_bar($location) {
-      wp_nav_menu(array(
-          'container' => false,                           // remove nav container
-          'container_class' => '',                        // class of container
-          'menu' => '',                                   // menu name
-          'menu_class' => '',                             // adding custom nav class
-          'theme_location' => $location,                  // where it's located in the theme
-          'before' => '',                                 // before each link <a>
-          'after' => '',                                  // after each link </a>
-          'link_before' => '',                            // before each link text
-          'link_after' => '',                             // after each link text
-          'depth' => 2,                                   // limit the depth of the nav
-          'fallback_cb' => false,                         // fallback function (see below)
-          'walker' => new Glm_Theme_Top_Bar_Walker()
-      ));
-  }
+    function glm_theme_top_bar() {
+        echo '<ul>';
+        echo glm_get_top_bar_nav_menu( 'boards' );
+        echo glm_get_top_bar_nav_menu( 'departments' );
+        echo glm_get_top_bar_nav_menu( 'calendar' );
+        echo glm_get_top_bar_nav_menu( 'township' );
+        echo '</ul>';
+    }
+}
+/**
+ * Alt Menus
+ */
+if ( ! function_exists( 'glm_theme_menus' ) ) {
+    function glm_theme_menus($location) {
+        echo '<ul>';
+        echo glm_get_top_bar_nav_menu( $location );
+        echo '</ul>';
+    }
+}
+
+function glm_get_top_bar_nav_menu( $theme_location )
+{
+    $menu = wp_nav_menu(array(
+        'echo'            => false,       // don't echo
+        'container'       => false,       // remove nav container
+        'container_class' => '',          // class of container
+        'menu'            => '',          // menu name
+        'menu_class'      => '',          // adding custom nav class
+        'theme_location'  => $theme_location, // where it's located in the theme
+        'before'          => '',          // before each link <a>
+        'after'           => '',          // after each link </a>
+        'link_before'     => '',          // before each link text
+        'link_after'      => '',          // after each link text
+        'depth'           => 2,           // limit the depth of the nav
+        'fallback_cb'     => false,       // fallback function (see below)
+        'walker'          => new Glm_Theme_Top_Bar_Walker()
+    ));
+    return preg_replace( array( '%^<ul[^>]*>%', '%</ul>$%' ), '', $menu );
 }
 
+
 /**
  * Mobile off-canvas
  */
@@ -175,10 +193,39 @@ function glm_get_menu_options()
  * @return void
  */
 function glm_side_menu($mobile = false) {
+
     global $post;
+   
     $sideMenu = $allMenu = $pageMenuId = array();
-    if (($locations = get_nav_menu_locations()) && isset($locations['top-bar'])) {
-        $menu       = wp_get_nav_menu_object($locations['top-bar']);
+    
+//    echo $post->ID;
+//    if (($locations = get_nav_menu_locations()) && isset($locations['top-bar-1']))      {
+//        $menu       = wp_get_nav_menu_object($locations['top-bar-1']);
+//     }
+    if(is_page(195) || 195 == $post->post_parent || is_in_tree(195)){
+        if (($locations = get_nav_menu_locations()) && isset($locations['boards'])) {
+            $menu       = wp_get_nav_menu_object($locations['boards']);
+        }
+    }
+
+    if(is_page(197) || 197 ==  $post->post_parent || is_in_tree(197)){
+        if (($locations = get_nav_menu_locations()) && isset($locations['departments'])) {
+            $menu       = wp_get_nav_menu_object($locations['departments']);
+        }
+    }
+
+    if(is_page(199) || 199 == $post->post_parent || is_in_tree(199)){
+        if (($locations = get_nav_menu_locations()) && isset($locations['calendar'])) {
+            $menu       = wp_get_nav_menu_object($locations['calendar']);
+        }
+    }
+    if(is_page(201) || 201 == $post->post_parent || is_in_tree(201)){
+        if (($locations = get_nav_menu_locations()) && isset($locations['township'])) {
+            $menu       = wp_get_nav_menu_object($locations['township']);
+        }
+      
+   }
+
         $menu_items = wp_get_nav_menu_items($menu->term_id);
         foreach ((array) $menu_items as $key => $menu_item) {
             $sideMenu[$menu_item->menu_item_parent][] = $menu_item;
@@ -208,9 +255,9 @@ function glm_side_menu($mobile = false) {
             // If the first element is title [Tabs] then this is a uber menu
             // custom item and we need to get the subs under that menu item
             // instead ($sideMenu[$subs[0]->ID])
-            if ($subs[0]->title == '[Tabs]') {
-                $subs = $sideMenu[$subs[0]->ID];
-            }
+//            if ($subs[0]->title == '[Tabs]') {
+//                $subs = $sideMenu[$subs[0]->ID];
+//            }
         } else if ($thisPageMenuParent)  {
             $pageHead  = $allMenu[$thisPageMenuParent];
             // get the subs for $thisPageMenuParent
@@ -220,7 +267,7 @@ function glm_side_menu($mobile = false) {
             // get Main level
             $subs = $sideMenu[0];
         }
-    }
+    
     if ($mobile) {
         echo '<ul>';
         echo '<li><a href="'.get_bloginfo('url').'">Home</a></li>';
@@ -228,13 +275,13 @@ function glm_side_menu($mobile = false) {
         if ($pageHead->target) {
             echo ' target="'.$pageHead->target.'"';
         }
-        echo '>'.strip_tags($pageHead->title).'</a><ul>';
+        echo '>'.$pageHead->title.'</a><ul>';
     } else {
-        echo '<h4><a href="'.$pageHead->url.'"';
+        echo '<h1><a href="'.$pageHead->url.'"';
         if ($pageHead->target) {
             echo ' target="'.$pageHead->target.'"';
         }
-        echo '>'.strip_tags($pageHead->title).'</a></h4>';
+        echo '>'.$pageHead->title.'</a></h1>';
         echo '<ul>';
     }
     foreach ($subs as $menu_item) {
@@ -242,12 +289,10 @@ function glm_side_menu($mobile = false) {
         if ($menu_item->target) {
             echo ' target="'.$menu_item->target.'"';
         }
-        echo '>'.strip_tags($menu_item->title) .'</a></li>';
+        echo '>'.$menu_item->title.'</a></li>';
     }
     if ($mobile) {
-         echo '</ul>';
+        echo '</ul>';
     }
     echo '</ul>';
-
 }
-
index 209139c..cc1185a 100644 (file)
@@ -9,7 +9,7 @@
             <div class="medium-7 columns secondary-nav-menu">
                 <nav class="large-12 columns top-bar-alt text-center show-for-medium-up opensearchserver.ignore" data-topbar role="navigation" data-options="sticky_on: large">
                     <section class="top-bar-section alt-menu">
-                        <?php glm_theme_top_bar('alt-menu'); ?>
+                        <?php glm_theme_menus('alt-menu'); ?>
                     </section>
                 </nav>
             </div>
@@ -29,7 +29,7 @@
         <div class="row row">
             <nav class="large-12 columns top-bar text-center show-for-medium-up opensearchserver.ignore" data-topbar role="navigation" data-options="sticky_on: large">
                 <section class="top-bar-section">
-                    <?php glm_theme_top_bar('top-bar'); ?>
+                    <?php glm_theme_top_bar(); ?>
                 </section>
             </nav>
             <nav class="tab-bar show-for-small-down">