Updating the side menu for this site
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 4 Mar 2016 17:16:17 +0000 (12:16 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 4 Mar 2016 17:16:17 +0000 (12:16 -0500)
Fixing some places where errors are being generated when WP debug is on

lib/navigation.php

index a162c63..7b7e4de 100644 (file)
@@ -164,28 +164,11 @@ function glm_get_menu_options()
     return $menu_options;
 }
 
-//function glm_side_menu() {
-//    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;
-//    } else {
-//        $ID = $parent->ID;
-//    }
-//    echo '<h2>'.get_the_title($ID).'</h2>';
-//    echo '<ul class="sidebar"><!-- begin -->'."\n";
-//    echo wp_list_pages( 'child_of='.$ID.'&title_li=&depth=1&echo=0');
-//    echo '</ul><!-- end -->'."\n";
-//}
 function glm_side_menu($mobile = false) {
-        global $post;
-    
+    global $post;
     // do not use appearance menu for the following page ID's or their ancestors
-        if( !is_page(array(3200, 3201,3202,3203)) && !is_tree(3200) && !is_tree(3201) && !is_tree(3202) && !is_tree(3203)){
-           
-            $sideMenu = $allMenu = $pageMenuId = array();
+    if( !is_page(array(3200, 3201,3202,3203)) && !is_tree(3200) && !is_tree(3201) && !is_tree(3202) && !is_tree(3203)) {
+        $sideMenu = $allMenu = $pageMenuId = array();
         if (($locations = get_nav_menu_locations()) && isset($locations['top-bar'])) {
             $menu       = wp_get_nav_menu_object($locations['top-bar']);
         }
@@ -212,69 +195,69 @@ function glm_side_menu($mobile = false) {
         }
         // does the current page (in the menu) have sub menu items?
         if (isset($sideMenu[$thisPageMenuId]) && !empty($sideMenu[$thisPageMenuId])) {
-            $pageHead  = $allMenu[$thisPageMenuId];
+            $pageHead  = (isset($allMenu[$thisPageMenuId])) ? $allMenu[$thisPageMenuId] :  (object) array('url' => '', 'target' => '', 'title' => '');
             // 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
             // 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
             $subs = $sideMenu[$thisPageMenuParent];
         } else {
-            $pageHead  = $allMenu[0];
+            $pageHead  = (isset($allMenu[0])) ? $allMenu[0] :  (object) array('url' => '', 'target' => '', 'title' => '');
             // get Main level
             $subs = $sideMenu[0];
         }
-    
-    if ($mobile) {
-        echo '<ul>';
-        echo '<li><a href="'.get_bloginfo('url').'">Home</a></li>';
-        echo '<li><a href="'.$pageHead->url.'"';
-        if ($pageHead->target) {
-            echo ' target="'.$pageHead->target.'"';
+
+        if ($mobile) {
+            echo '<ul>';
+            echo '<li><a href="'.get_bloginfo('url').'">Home</a></li>';
+            echo '<li><a href="'.$pageHead->url.'"';
+            if ($pageHead->target) {
+                echo ' target="'.$pageHead->target.'"';
+            }
+            echo '>'.$pageHead->title.'</a><ul>';
+        } else {
+            echo '<h2><a href="'.$pageHead->url.'"';
+            if ($pageHead->target) {
+                echo ' target="'.$pageHead->target.'"';
+            }
+            echo '>'.$pageHead->title.'</a></h2>';
+            echo '<ul class="sidebar">';
         }
-        echo '>'.$pageHead->title.'</a><ul>';
-    } else {
-        echo '<h2><a href="'.$pageHead->url.'"';
-        if ($pageHead->target) {
-            echo ' target="'.$pageHead->target.'"';
+        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>';
         }
-        echo '>'.$pageHead->title.'</a></h2>';
-        echo '<ul class="sidebar">';
-    }
-    foreach ($subs as $menu_item) {
-        echo '<li><a href="'.$menu_item->url.'"';
-        if ($menu_item->target) {
-            echo ' target="'.$menu_item->target.'"';
+        if ($mobile) {
+            echo '</ul>';
         }
-        echo '>'.$menu_item->title.'</a></li>';
-    }
-    if ($mobile) {
         echo '</ul>';
-    }
-    echo '</ul>';
-// using page menu here for the listed page ID's above
-} else {
-  
-    $parents = get_post_ancestors($post->ID);
-    $id = ($parents) ? $parents[count($parents)-1]: $post->ID;
-    $parent = get_page( $id );
-    if ($id == 0) {
-        $ID = $post->ID;
+        // using page menu here for the listed page ID's above
     } else {
-        $ID = $parent->ID;
-    }
-    echo '<h2>'.get_the_title($ID).'</h2>';
-    echo '<ul class="sidebar"><!-- begin -->'."\n";
-    echo wp_list_pages( 'child_of='.$ID.'&title_li=&depth=1&echo=0');
-    echo '</ul><!-- end -->'."\n";       
+
+        $parents = get_post_ancestors($post->ID);
+        $id = ($parents) ? $parents[count($parents)-1]: $post->ID;
+        $parent = get_page( $id );
+        if ($id == 0) {
+            $ID = $post->ID;
+        } else {
+            $ID = $parent->ID;
         }
+        echo '<h2>'.get_the_title($ID).'</h2>';
+        echo '<ul class="sidebar"><!-- begin -->'."\n";
+        echo wp_list_pages( 'child_of='.$ID.'&title_li=&depth=1&echo=0');
+        echo '</ul><!-- end -->'."\n";
+    }
 }
-           
-           
+
+