update nav functions
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 13 Jun 2017 20:13:46 +0000 (16:13 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 13 Jun 2017 20:13:46 +0000 (16:13 -0400)
lib/navigation.php

index 08f8f00..d229765 100644 (file)
@@ -2,7 +2,8 @@
 
 register_nav_menus(array(
   'top-bar' => 'Site Navigation',
-   'mobile' => 'Mobile Menu'
+  'mobile' => 'Mobile Menu',
+  'sidenav' => 'Side Nav'
 ));
 
 /**
@@ -32,7 +33,7 @@ if ( ! function_exists( 'glm_theme_top_bar' ) ) {
  */
 if ( ! function_exists( 'glm_theme_mobile_off_canvas' ) ) {
     function glm_theme_mobile_off_canvas() {
-       
+
         echo '<div class="left-off-canvas-list">';
         echo '<ul>';
         echo '<li class="page_item"><a href="' . get_bloginfo('url') . '">HOME</a></li>';
@@ -152,19 +153,70 @@ function glm_get_menu_options()
     return $menu_options;
 }
 
-function glm_side_menu() {
+function glm_side_menu($mobile = false) {
+
     global $post;
-    $parents = get_post_ancestors($post->ID);
-    $id = ($parents) ? $parents[count($parents)-1]: $post->ID;
-    $parent = get_page( $id );
-    if ($id == 0) {
-        $ID = $post->ID;
+
+    $sideMenu = $allMenu = $pageMenuId = array();
+
+    $menu = wp_get_nav_menu_object($locations['sidenav']);
+
+    $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;
+        $allMenu[$menu_item->ID] = $menu_item;
+        if ($menu_item->object_id == $post->ID) {
+            $pageMenuId[] = $menu_item;
+        }
+    }
+    if (count($pageMenuId) > 1) {
+        $thisPageMenuId = (isset($pageMenuId[1])) ? $pageMenuId[1]->ID : 0;
+        $thisPageMenuParent = (isset($pageMenuId[1])) ? $pageMenuId[1]->menu_item_parent : 0;
+        foreach ($pageMenuId as $men) {
+            if (isset($sideMenu[$men->ID]) && !empty($sideMenu[$men->ID])) {
+                $thisPageMenuId     = $men->ID;
+                $thisPageMenuParent = $men->menu_item_parent;
+            }
+        }
     } else {
-        $ID = $parent->ID;
+        $thisPageMenuId = (isset($pageMenuId[0])) ? $pageMenuId[0]->ID : 0;
+        $thisPageMenuParent = (isset($pageMenuId[0])) ? $pageMenuId[0]->menu_item_parent : 0;
     }
-    echo '<h1>'.get_the_title($ID).'</h1>';
-    echo '<ul class="sidebar"><!-- begin -->'."\n";
-    echo wp_list_pages( 'child_of='.$ID.'&title_li=&depth=1&echo=0');
-    echo '</ul><!-- end -->'."\n";
+    // does the current page (in the menu) have sub menu items?
+    if (isset($sideMenu[$thisPageMenuId]) && !empty($sideMenu[$thisPageMenuId])) {
+        $pageHead  = $allMenu[$thisPageMenuId];
+        // get the subs for $thisPageMenuId
+        $subs = $sideMenu[$thisPageMenuId];
+        // 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
+    } else if ($thisPageMenuParent)  {
+        $pageHead  = $allMenu[$thisPageMenuParent];
+        // get the subs for $thisPageMenuParent
+        $subs = $sideMenu[$thisPageMenuParent];
+    } else {
+        $pageHead  = $allMenu[0];
+        // get Main level
+        $subs = $sideMenu[0];
+    }
+
+    if(is_page(142) || 142 == $post->post_parent || is_tree(142)){
+        echo '<h1><a href="'. get_permalink(142).'"';
+        echo '> CHAMBER </a></h1>';
+    } else {
+        echo '<h1><a href="'. get_permalink(137).'"';
+        echo '> COMMUNITY </a></h1>';
+    }
+    echo '<ul>';
+    foreach ($subs as $menu_item) {
+        echo '<li><a href="'.$menu_item->url.'"';
+        if ($menu_item->target) {
+            echo ' target="'.$menu_item->target.'"';
+        }
+        echo '>'.$menu_item->title.'</a></li>';
+    }
+    if ($mobile) {
+        echo '</ul>';
+    }
+    echo '</ul>';
 }