From: Anthony Talarico Date: Wed, 14 Dec 2016 13:34:57 +0000 (-0500) Subject: summary: adding 2 new appearance menus for travel pros and contact us X-Git-Tag: v1.0.0^2~74 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=8bef110a3b7207de366e7311409c78e71776a7e1;p=WP-Themes%2Fmackinawareavb.git summary: adding 2 new appearance menus for travel pros and contact us detail: adding new sidebar with a template for the pages that need a sidebar containing pages from their respectice appearance menus --- diff --git a/lib/navigation.php b/lib/navigation.php index 3dc1eef..9dfa304 100644 --- a/lib/navigation.php +++ b/lib/navigation.php @@ -3,9 +3,26 @@ register_nav_menus(array( 'top-bar' => 'Site Navigation', 'members-only' => 'Members Only', - 'day-trips' => 'Day Trips' + 'day-trips' => 'Day Trips', + 'travel-pro' => 'Travel Professionals', + 'contact-us' => 'Contact Us' )); +function is_tree( $pid ) { + global $post; + + if ( is_page($pid) ) + return true; + + $anc = get_post_ancestors( $post->ID ); + foreach ( $anc as $ancestor ) { + if( is_page() && $ancestor == $pid ) { + return true; + } + } + return false; +} + /** * Top Bar */ @@ -171,4 +188,94 @@ function glm_side_menu() { echo wp_list_pages( 'child_of='.$ID.'&title_li=&depth=1&echo=0'); echo ''."\n"; } +function glm_sidebar_menu($mobile = false) { + global $post; + + $sideMenu = $allMenu = $pageMenuId = array(); + +// echo $post->ID; +// if (($locations = get_nav_menu_locations()) && isset($locations['top-bar-1'])) { +// $menu = wp_get_nav_menu_object($locations['top-bar-1']); +// } + if(is_page(20) || 20 == $post->post_parent || is_tree(20)){ + if (($locations = get_nav_menu_locations()) && isset($locations['travel-pro'])) { + $menu = wp_get_nav_menu_object($locations['travel-pro']); + } + } + if(is_page(21) || 21 == $post->post_parent || is_tree(21)){ + if (($locations = get_nav_menu_locations()) && isset($locations['contact-us'])) { + $menu = wp_get_nav_menu_object($locations['contact-us']); + } + } + $menu_items = wp_get_nav_menu_items($menu->term_id); + //echo '
', print_r($menu_items), '
'; + 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 '