From 41d0f6cc6690931701269d48ac3d381705c0de6d Mon Sep 17 00:00:00 2001 From: Anthony Talarico Date: Wed, 17 Feb 2016 09:07:53 -0500 Subject: [PATCH] testing landing page gallery and sidebar menus --- landing-page.php | 21 ++++++++++ lib/navigation.php | 102 +++++++++++++++++++++++++++++++++++++++------ 2 files changed, 110 insertions(+), 13 deletions(-) diff --git a/landing-page.php b/landing-page.php index 5ff3e69..a7538f4 100644 --- a/landing-page.php +++ b/landing-page.php @@ -20,6 +20,26 @@ Template Name: Landing Page
diff --git a/lib/navigation.php b/lib/navigation.php index feea943..c6f373d 100644 --- a/lib/navigation.php +++ b/lib/navigation.php @@ -163,20 +163,96 @@ 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; +//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 '

'.get_the_title($ID).'

'; +// echo ''."\n"; +//} +function glm_side_menu($mobile = false) { + global $post; + + $sideMenu = $allMenu = $pageMenuId = array(); + 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 (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 { + $thisPageMenuId = (isset($pageMenuId[0])) ? $pageMenuId[0]->ID : 0; + $thisPageMenuParent = (isset($pageMenuId[0])) ? $pageMenuId[0]->menu_item_parent : 0; + } + // 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 + // instead ($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]; + // get Main level + $subs = $sideMenu[0]; + } + + if ($mobile) { + echo '