From 44a87215bfff93df111ba3d9cd9e4308e5413f58 Mon Sep 17 00:00:00 2001 From: Anthony Talarico Date: Mon, 20 Jun 2016 10:21:24 -0400 Subject: [PATCH] using appearance menu for sidebar instead of pages --- js/app.js | 11 ++++ js/custom/pageSetup.js | 11 ++++ lib/navigation.php | 116 +++++++++++++++++++++++++++++++++++------ 3 files changed, 121 insertions(+), 17 deletions(-) diff --git a/js/app.js b/js/app.js index acf7390..f01b2a5 100644 --- 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"); + } + }); + }); diff --git a/js/custom/pageSetup.js b/js/custom/pageSetup.js index 7aa110a..5d7bb64 100644 --- a/js/custom/pageSetup.js +++ b/js/custom/pageSetup.js @@ -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"); + } + }); + }); diff --git a/lib/navigation.php b/lib/navigation.php index 9a27098..c4f623d 100644 --- a/lib/navigation.php +++ b/lib/navigation.php @@ -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 '
Gaslight News
'; +// } else { +// echo '
'.get_the_title($ID).'
'; +// } +// echo ''."\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 '
Gaslight News
'; + // 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 '
'.get_the_title($ID).'
'; + $pageHead = (isset($allMenu[0])) ? $allMenu[0] : (object) array('url' => '', 'target' => '', 'title' => ''); + // get Main level + $subs = $sideMenu[0]; } - echo ''."\n"; + + if ($mobile) { + echo '