adding sections to separate the areas of the site, for the sidebar menus and the...
authorAnthony Talarico <talarico@gaslightmedia.com>
Wed, 26 Jul 2017 14:22:56 +0000 (10:22 -0400)
committerAnthony Talarico <talarico@gaslightmedia.com>
Wed, 26 Jul 2017 14:22:56 +0000 (10:22 -0400)
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
lib/navigation.php
parts/section-interior.php [new file with mode: 0644]
parts/template-interior.php [new file with mode: 0644]
sections/interior-page.php
sections/top-bar.php

index 3fc9228..5d2fcb6 100644 (file)
@@ -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');
index 589569e..2a82ddb 100644 (file)
@@ -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 '</ul><!-- end -->'."\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 '<ul>';
         echo '<li><a href="'.get_bloginfo('url').'">Home</a></li>';
diff --git a/parts/section-interior.php b/parts/section-interior.php
new file mode 100644 (file)
index 0000000..3b33f3f
--- /dev/null
@@ -0,0 +1,27 @@
+<main class="page-inside">
+    <div id="content-wrapper">
+        <?php echo glm_get_header();?>
+         <?php //$post_content = get_post($post->ID); ?>
+          <div class="row column">
+                    <?php if(!is_front_page()) {
+   
+                            get_template_part('parts/left-sidebar');
+              
+                        echo "<div class=\"small-12 medium-8 large-6 columns\">";
+                        if(function_exists('bcn_display') && !is_front_page()) 
+                        {
+                            echo "<div class=\"breadcrumbs\">";
+                            bcn_display();
+//                            get_template_part('parts/share-this');
+                            echo "</div>";
+                        }
+                        get_template_part('parts/main-content');
+                        echo "</div>";
+                        echo "<div id='sidebar' class='small-12 medium-4 large-3 show-for-large columns'>";
+                            get_sidebar();
+                        echo "</div>";
+                    } ?>
+            <?php// } ?>
+        </div>
+    </div>
+</main>
\ No newline at end of file
diff --git a/parts/template-interior.php b/parts/template-interior.php
new file mode 100644 (file)
index 0000000..4e5395b
--- /dev/null
@@ -0,0 +1,21 @@
+<main class="page-inside">
+    <div id="content-wrapper">
+        <?php echo glm_get_header();?>
+         <?php //$post_content = get_post($post->ID); ?>
+          <div class="row column">
+                    <?php if(!is_front_page()) {
+                        echo "<div class=\"small-12 columns\">";
+                            if(function_exists('bcn_display') && !is_front_page()) 
+                            {
+                                echo "<div class=\"breadcrumbs\">";
+                                bcn_display();
+    //                            get_template_part('parts/share-this');
+                                echo "</div>";
+                            }
+                            get_template_part('parts/main-content');
+                        echo "</div>";
+                    } ?>
+            <?php// } ?>
+        </div>
+    </div>
+</main>
\ No newline at end of file
index 4f0c20b..fa425e4 100644 (file)
@@ -1,33 +1,13 @@
 <div id="interior-header-area">
 
 </div>
-<main class="page-inside">
-    <div id="content-wrapper">
-        <?php echo glm_get_header();?>
-         <?php //$post_content = get_post($post->ID); ?>
-          <div class="row column">
-                    <?php if(!is_front_page()) {
-   
-                            get_template_part('parts/left-sidebar');
-              
-                        echo "<div class=\"small-12 medium-8 large-6 columns\">";
-                        if(function_exists('bcn_display') && !is_front_page()) 
-                        {
-                            echo "<div class=\"breadcrumbs\">";
-                            bcn_display();
-//                            get_template_part('parts/share-this');
-                            echo "</div>";
-                        }
-                        get_template_part('parts/main-content');
-                        echo "</div>";
-                        echo "<div id='sidebar' class='small-12 medium-4 large-3 show-for-large columns'>";
-                            get_sidebar();
-                        echo "</div>";
-                    } ?>
-            <?php// } ?>
-        </div>
-    </div>
-</main>
+<?php if(get_abs_parent()){
+    get_template_part('parts/section-interior');
+} else {
+    get_template_part('parts/template-interior');
+}
+?>
+
 
 <!--        <div id="page-title" class="text-center">
             
index d6e6d83..52769c7 100644 (file)
@@ -1,6 +1,7 @@
-<?php $template = get_page_template_slug($post->ID); 
-$templates = array('chamber.php', 'visitor.php', 'government.php', 'economic.php');
-if( in_array($template, $templates) ){ ?>
+<?php 
+$page = get_post(get_abs_parent());
+$page_slug = $page->post_name;
+if( in_array(get_page_template(), page_templates()) || in_array($page_slug,get_landing_pages()) ){ ?>
     <div id="interior-menu">
         <div class="top-bar">
             <div class="top-bar-left">
@@ -10,27 +11,40 @@ if( in_array($template, $templates) ){ ?>
             <div class="top-bar-left">
 <?php }
 
-switch($template){
-    case "government.php": 
-        glm_theme_gov_navigation(); 
-        break;
-    case "chamber.php":
-
-        glm_theme_chamber_navigation(); 
-        break;
-    case "visitor.php": 
-
-        glm_theme_cvb_navigation() ;
-        break;
-    case "economic.php": 
-
-        glm_theme_economic_navigation();
-        break;
-    default: 
-        glm_theme_top_bar();
-        break;
-}
-?>
+if(!get_abs_parent()){
+    $template = get_page_template();
+    if($template){
+       if(strpos($template,"government.php") !== false){
+          glm_theme_gov_navigation(); 
+       }else if(strpos($template,"government.php") !== false){
+           glm_theme_chamber_navigation(); 
+       }else if(strpos($template,"visitor.php") !== false){
+           glm_theme_cvb_navigation();
+       }else if(strpos($template,"economic.php") !== false){
+           glm_theme_economic_navigation();
+       }
+    } else {
+         glm_theme_top_bar();
+    }
+} else {
+    switch($page_slug){
+        case "government-townships": 
+            glm_theme_gov_navigation(); 
+            break;
+        case "chamber-of-commerce":
+            glm_theme_chamber_navigation(); 
+            break;
+        case "visitor-information": 
+            glm_theme_cvb_navigation() ;
+            break;
+        case "economic-development": 
+            glm_theme_economic_navigation();
+            break;
+        default: 
+            glm_theme_top_bar();
+            break;
+    }
+} ?>
         </div>
     </div>
 </div>
\ No newline at end of file