summary: adding 2 new appearance menus for travel pros and contact us
authorAnthony Talarico <talarico@gaslightmedia.com>
Wed, 14 Dec 2016 13:34:57 +0000 (08:34 -0500)
committerAnthony Talarico <talarico@gaslightmedia.com>
Wed, 14 Dec 2016 13:34:57 +0000 (08:34 -0500)
detail: adding new sidebar with a template for the pages that need a sidebar
containing pages from their respectice appearance menus

lib/navigation.php
lib/templates.php
parts/sidebar-menu.php [new file with mode: 0644]
sections/interior-page.php

index 3dc1eef..9dfa304 100644 (file)
@@ -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 '</ul><!-- end -->'."\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 '<pre>', print_r($menu_items), '</pre>';
+        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 '<ul>';
+        echo '<li><a href="'.get_bloginfo('url').'">Home</a></li>';
+        echo '<li><a href="'.$pageHead->url.'"';
+        if ($pageHead->target) {
+            echo ' target="'.$pageHead->target.'"';
+        }
+        echo '>'.$pageHead->title.'</a><ul>';
+    } else {
+        echo '<h1><a href="'.$pageHead->url.'"';
+        if ($pageHead->target) {
+            echo ' target="'.$pageHead->target.'"';
+        }
+        echo '>'.$pageHead->title.'</a></h1>';
+        echo '<ul>';
+    }
+    foreach ($subs as $menu_item) {
+        echo '<li><a href="'.$menu_item->url.'"';
+        if ($menu_item->target) {
+            echo ' target="'.$menu_item->target.'"';
+        }
+        echo '>'.$menu_item->title.'</a></li>';
+    }
+    if ($mobile) {
+        echo '</ul>';
+    }
+    echo '</ul>';
+}
index d51994b..1292a50 100644 (file)
@@ -52,8 +52,9 @@ add_filter( 'custom_page_templates', function( $now_templates ) {
     // this template by its slug in our index.php using get_page_template_slug
     // Below are some commented examples of custom quasi-templates.
     $templates = array(
-      'members-only' => 'Members Only',
-     'event-detail' => 'Event Detail'
+      'members-only'    => 'Members Only',
+      'event-detail'    => 'Event Detail',
+      'side-bar'        => 'Side Bar' 
     //    'any-template-slug' => 'Sample Template' ,
     );
 
diff --git a/parts/sidebar-menu.php b/parts/sidebar-menu.php
new file mode 100644 (file)
index 0000000..e7e3534
--- /dev/null
@@ -0,0 +1,6 @@
+<div id="side-nav" class="show-for-large-up" data-equalizer-watch>
+    <div class="row collapse">
+        <h2 class="text-center"></h2>
+            <?php glm_sidebar_menu(); ?>
+    </div>
+</div>
index 3caa85e..f417b23 100644 (file)
                                         </div>
                                     </div>
                                 </div>
+                            <?php } else if (get_page_template_slug( $post->ID ) === "side-bar"){ ?>
+                                <div class="row members-only-template">
+                                    <div class="sidebar-wrapper small-12 medium-3 columns small-text-center medium-text-left members-only-template">
+                                        <?php get_template_part('parts/sidebar-menu') ?>
+                                    </div>
+                                    <div id="main-content" class="small-12 medium-9 columns">
+                                            <?php get_template_part('parts/main-content'); ?>
+                                    </div>
+                                </div>
                             <?php } else { ?>
                                 <div class="row">
                                     <?php get_template_part('parts/main-content'); ?>
                                 </div>
-                            <?php } ?>
+                           <?php } ?>
                         </div>
                     </main>
\ No newline at end of file