Update the side navigation.
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 23 Jun 2015 18:36:22 +0000 (14:36 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 23 Jun 2015 18:36:22 +0000 (14:36 -0400)
Now it show the proper level and is based on the custom wordpress menu
instead of the pages.

functions.php

index 40464cd..e0e7e50 100644 (file)
@@ -177,18 +177,42 @@ function glm_get_header() {
 
 function glm_side_menu() {
     global $post;
+    //echo '<pre>'.print_r($post, true).'</pre>';
     $parents = get_post_ancestors($post->ID);
-    $id = ($parents) ? $parents[count($parents)-1]: $post->ID;
+    $id = (count($parents) > 1) ? $parents[0]: $post->ID;
     $parent = get_page( $id );
     if ($id == 0) {
         $ID = $post->ID;
     } else {
         $ID = $parent->ID;
     }
-    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";
+    //echo '<pre>'.print_r($ID, true).'</pre>';
+    if (($locations = get_nav_menu_locations()) && isset($locations['top-bar'])) {
+        $menu = wp_get_nav_menu_object($locations['top-bar']);
+        $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) {
+                $section = $menu_item->ID;
+                $section_parent = $menu_item->menu_item_parent;
+            }
+        }
+        if (isset($sideMenu[$section]) && !empty($sideMenu[$section])) {
+            $pageHead  = $allMenu[$section];
+            $side_menu = $sideMenu[$section];
+        } else {
+            $pageHead  = $allMenu[$section_parent];
+            $side_menu = $sideMenu[$section_parent];
+        }
+    }
+    echo '<h1>'.$pageHead->title.'</h1>';
+    echo '<ul>';
+    foreach ($side_menu as $menu_item) {
+        echo '<li><a href="'.$menu_item->url.'">'.$menu_item->title.'</a></li>';
+    }
+    echo '</ul>';
+
 }
 
 add_action('wp_enqueue_scripts', 'glm_site_scripts');