using appearance menu for sidebar instead of pages
authorAnthony Talarico <talarico@gaslightmedia.com>
Mon, 20 Jun 2016 14:21:24 +0000 (10:21 -0400)
committerAnthony Talarico <talarico@gaslightmedia.com>
Mon, 20 Jun 2016 14:21:24 +0000 (10:21 -0400)
js/app.js
js/custom/pageSetup.js
lib/navigation.php

index acf7390..f01b2a5 100644 (file)
--- a/js/app.js
+++ b/js/app.js
@@ -59,4 +59,15 @@ $(document).ready(function () {
     
     $('#submit-button > td').attr("colspan",2);
     
+    var url = window.location.href;
+    // 'current' class style to sidebar item that matches the current url
+      $('ul.sidebar li a').each(function() {
+        if ($(this).prop('href') == url) {
+            $(this).addClass('current_page_item');
+        }
+        if($(this).attr("class") === "current_page_item"){
+            $(this).parent("li").addClass("current_page_item");
+        }
+    });
+    
 });
index 7aa110a..5d7bb64 100644 (file)
@@ -50,4 +50,15 @@ $(document).ready(function () {
     
     $('#submit-button > td').attr("colspan",2);
     
+    var url = window.location.href;
+    // 'current' class style to sidebar item that matches the current url
+      $('ul.sidebar li a').each(function() {
+        if ($(this).prop('href') == url) {
+            $(this).addClass('current_page_item');
+        }
+        if($(this).attr("class") === "current_page_item"){
+            $(this).parent("li").addClass("current_page_item");
+        }
+    });
+    
 });
index 9a27098..c4f623d 100644 (file)
@@ -140,28 +140,110 @@ function glm_get_menu_options()
     return $menu_options;
 }
 
-function glm_side_menu() {
+//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 (is_post_type("post") || is_home() ) {
+//        $id = 511;
+//        $parent = get_page( 96 );
+//    }
+//    
+//    if ($id == 0) {
+//        $ID = $post->ID;
+//    } else {
+//        $ID = $parent->ID;
+//    }
+//    if (is_post_type("post") || is_home() ) {
+//        echo '<h6>Gaslight News</h6>';
+//    } else {
+//        echo '<h6>'.get_the_title($ID).'</h6>';
+//    }
+//    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;
-    $parents = get_post_ancestors($post->ID);
-    $id = ($parents) ? $parents[count($parents)-1]: $post->ID;
-    $parent = get_page( $id );
-    if (is_post_type("post") || is_home() ) {
-        $id = 511;
-        $parent = get_page( 96 );
+    $sideMenu = $allMenu = $pageMenuId = array();
+//     do not use appearance menu for the following page ID's or their ancestors
+
+    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) {
+            $pageMenuId[] = $menu_item;
+        }
     }
-    
-    if ($id == 0) {
-        $ID = $post->ID;
+    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;
     }
-    if (is_post_type("post") || is_home() ) {
-        echo '<h6>Gaslight News</h6>';
+    // does the current page (in the menu) have sub menu items?
+    if (isset($sideMenu[$thisPageMenuId]) && !empty($sideMenu[$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 == 'Test') {
+             $subs = $sideMenu[$subs[0]->ID];
+         }
+    } else if ($thisPageMenuParent)  {
+        $pageHead  = $allMenu[$thisPageMenuParent];
+        // get the subs for $thisPageMenuParent
+        $subs = $sideMenu[$thisPageMenuParent];
     } else {
-        echo '<h6>'.get_the_title($ID).'</h6>';
+        $pageHead  = (isset($allMenu[0])) ? $allMenu[0] :  (object) array('url' => '', 'target' => '', 'title' => '');
+        // get Main level
+        $subs = $sideMenu[0];
     }
-    echo '<ul class="sidebar"><!-- begin -->'."\n";
-    echo wp_list_pages( 'child_of='.$ID.'&title_li=&depth=1&echo=0');
-    echo '</ul><!-- end -->'."\n";
+
+    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 '<h6>';
+        if ($pageHead->target) {
+            echo ' target="'.$pageHead->target.'"';
+        }
+        echo $pageHead->title.'</h6>';
+        echo '<ul class="sidebar">';
+    }
+    foreach ($subs as $menu_item) {
+        echo '<li class="page-item"><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>';
 }