From: Steve Sutton Date: Tue, 23 Jun 2015 18:36:22 +0000 (-0400) Subject: Update the side navigation. X-Git-Tag: v1.0.0~49^2~145 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=a2a4d8e809dbc1bf01f271998d16ec36e00a6c3a;p=WP-Themes%2Fcrawfordco.git Update the side navigation. Now it show the proper level and is based on the custom wordpress menu instead of the pages. --- diff --git a/functions.php b/functions.php index 40464cd..e0e7e50 100644 --- a/functions.php +++ b/functions.php @@ -177,18 +177,42 @@ function glm_get_header() { function glm_side_menu() { global $post; + //echo '
'.print_r($post, true).'
'; $parents = get_post_ancestors($post->ID); - $id = ($parents) ? $parents[count($parents)-1]: $post->ID; + $id = (count($parents) > 1) ? $parents[0]: $post->ID; $parent = get_page( $id ); if ($id == 0) { $ID = $post->ID; } else { $ID = $parent->ID; } - echo '

'.get_the_title($ID).'

'; - echo ''."\n"; + //echo '
'.print_r($ID, true).'
'; + 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) { + $section = $menu_item->ID; + $section_parent = $menu_item->menu_item_parent; + } + } + if (isset($sideMenu[$section]) && !empty($sideMenu[$section])) { + $pageHead = $allMenu[$section]; + $side_menu = $sideMenu[$section]; + } else { + $pageHead = $allMenu[$section_parent]; + $side_menu = $sideMenu[$section_parent]; + } + } + echo '

'.$pageHead->title.'

'; + echo ''; + } add_action('wp_enqueue_scripts', 'glm_site_scripts');