From 491f0571087918bdb8f1ed7f7756bb10cd77fdbd Mon Sep 17 00:00:00 2001 From: Anthony Talarico Date: Wed, 26 Jul 2017 10:22:56 -0400 Subject: [PATCH] adding sections to separate the areas of the site, for the sidebar menus and the topbars adding separate theme files to partition the site's different areas. adding helper functions in the functions file to get page templates, slugs, ids and what not. adding navigation side menu function to pull appearance menus --- lib/misc.php | 28 ++++++++ lib/navigation.php | 124 ++++++++++++++++++++++++------------ parts/section-interior.php | 27 ++++++++ parts/template-interior.php | 21 ++++++ sections/interior-page.php | 34 ++-------- sections/top-bar.php | 62 +++++++++++------- 6 files changed, 205 insertions(+), 91 deletions(-) create mode 100644 parts/section-interior.php create mode 100644 parts/template-interior.php diff --git a/lib/misc.php b/lib/misc.php index 3fc9228..5d2fcb6 100644 --- a/lib/misc.php +++ b/lib/misc.php @@ -60,6 +60,34 @@ if (!function_exists('is_in_tree')) { } } +if (!function_exists('page_templates')) { + function page_templates(){ + return array('chamber.php', 'visitor.php', 'government.php', 'economic.php'); + } +} +if (!function_exists('get_landing_pages')) { + function get_landing_pages(){ + return array('government-townships', 'chamber-of-commerce', 'visitor-information', 'economic-development'); + } +} + +if (!function_exists('get_abs_parent')) { + function get_abs_parent(){ + global $post; + $parents = get_post_ancestors($post->ID); + + return end($parents); + } +} + +if (!function_exists('get_page_template')) { + function get_page_template(){ + global $post; + + return get_page_template_slug($post->ID); + } +} + // Start of the Contextual/Highlight Search functions function mytheme_init() { remove_action('thematic_searchloop', 'thematic_search_loop'); diff --git a/lib/navigation.php b/lib/navigation.php index 589569e..2a82ddb 100644 --- a/lib/navigation.php +++ b/lib/navigation.php @@ -3,7 +3,7 @@ register_nav_menus(array( 'top-bar' => 'Site Navigation', 'footer' => 'Footer Navigation', - 'second-header' => 'Secondary Header Navigation', + 'second-header' => 'Secondary Header Navigation', 'gov-nav' => 'Government Navigation', 'cvb-nav' => 'CVB Navigation', 'edc-nav' => 'Economic Development Navigation', @@ -261,53 +261,97 @@ function glm_get_menu_options() // echo wp_list_pages( 'child_of='.$ID.'&title_li=&depth=1&echo=0'); // 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; - } + $landing_pages = array('government-townships', 'chamber-of-commerce', 'visitor-information', 'economic-development'); + $page_ids = array(); + + foreach($landing_pages as $page){ + $args = array( + 'name' => $page, + 'post_type' => 'page', + 'post_status' => 'publish', + 'numberposts' => 1 + ); + $page_ids[$page] = get_posts($args); + } + $gov = $page_ids['government-townships'][0]->ID; + $cvb = $page_ids['visitor-information'][0]->ID; + $ecd = $page_ids['economic-development'][0]->ID; + $chmb = $page_ids['chamber-of-commerce'][0]->ID; + + if(is_page($gov) || $gov == $post->post_parent || is_in_tree($gov)){ + echo "GOV"; + if (($locations = get_nav_menu_locations()) && isset($locations['gov-nav'])) { + $menu = wp_get_nav_menu_object($locations['gov-nav']); } - 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; + } + if(is_page($cvb) || $cvb == $post->post_parent || is_in_tree($cvb)){ + echo "CVB"; + if (($locations = get_nav_menu_locations()) && isset($locations['cvb-nav'])) { + $menu = wp_get_nav_menu_object($locations['cvb-nav']); } - // 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]; + } + if(is_page($ecd) || $ecd == $post->post_parent || is_in_tree($ecd)){ + echo "ECON"; + if (($locations = get_nav_menu_locations()) && isset($locations['edc-nav'])) { + $menu = wp_get_nav_menu_object($locations['edc-nav']); + } + } + if(is_page($chmb) || $chmb == $post->post_parent || is_in_tree($chmb)){ + echo "CHAMBER"; + if (($locations = get_nav_menu_locations()) && isset($locations['chamber-nav'])) { + $menu = wp_get_nav_menu_object($locations['chamber-nav']); + } + } + + $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 if ($thisPageMenuParent) { - $pageHead = $allMenu[$thisPageMenuParent]; - // get the subs for $thisPageMenuParent - $subs = $sideMenu[$thisPageMenuParent]; - } else { - $pageHead = $allMenu[0]; - // get Main level - $subs = $sideMenu[0]; } + } 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 '