Work on menu
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 3 Apr 2015 15:04:04 +0000 (11:04 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 3 Apr 2015 15:04:04 +0000 (11:04 -0400)
Have to find way to get the main level pages without using theme.ini.
Since the pages have different id's and really can only use the page
slug names to build the main level pages up.

functions.php
theme.ini [deleted file]

index 49e68f1..271f1e1 100644 (file)
@@ -47,6 +47,36 @@ function glm_get_menu_options()
  */
 function glm_page_menu($parent = 0, $class = '')
 {
+    static $mainLevelPages, $mainLevelPageCount, $last, $mainLevel;
+    if (!$mainLevel) {
+        $mainPages = get_pages(array(
+            'post_type'   => 'page',
+            'parent'      => 0,
+            'number'      => '',
+            'exclude'     => $frontPageId,
+            'post_status' => 'publish',
+            'sort_order'  => 'asc',
+            'sort_column' => 'menu_order'
+        ));
+        foreach ($mainPages as $mPage) {
+            $pageNames = array(
+                'museum-ship-valley-camp',
+                'tower-of-history',
+                'river-of-history-museum',
+                'kemp-marina',
+                'water-street-historic-block'
+            );
+            if (in_array($mPage->post_name, $pageNames)) {
+                $mainLevel[] = $mPage->ID;
+            }
+        }
+    }
+    if (!$mainLevelPageCount) {
+        $mainLevelPageCount = array();
+    }
+    if (!$last) {
+        $last = array();
+    }
     $menuConfig   = glm_get_menu_options();
     $frontPageId  = get_option('page_on_front');
     $parents      = array();
@@ -59,64 +89,103 @@ function glm_page_menu($parent = 0, $class = '')
         'sort_order'  => 'asc',
         'sort_column' => 'menu_order'
     );
-    if ($parent == 0 && $menuConfig['menu_options']['main_level_pages']) {
-        $args['include'] = $menuConfig['menu_options']['main_level_pages'];
-    }
+    $args['include'] = (!empty($mainLevel) && $parent == 0) ? implode(',', $mainLevel): '';
     $pages = get_pages($args);
-    $mainLevelPageCount = array();
     echo '<ul'.(($class)?' class="'.$class.'"':'').'><!-- begin -->'."\n";
+    if (!$mainLevelPages) {
+        $mainLevelPages = array();
+        $pageCountIterator = 1;
+        $vertLimit = 4;
+        foreach ($pages as $page) {
+            if ($parent == 0) {
+                switch ($page->post_name) {
+                case 'museum-ship-valley-camp':
+                    $mainLevelPages[$page->ID] = $page->post_name;
+                    if ($pageCountIterator >= $vertLimit) {
+                        $last[] = $page->ID;
+                    }
+                    break;
+                case 'tower-of-history':
+                    $mainLevelPages[$page->ID] = $page->post_name;
+                    if ($pageCountIterator >= $vertLimit) {
+                        $last[] = $page->ID;
+                    }
+                    break;
+                case 'river-of-history-museum':
+                    $mainLevelPages[$page->ID] = $page->post_name;
+                    if ($pageCountIterator >= $vertLimit) {
+                        $last[] = $page->ID;
+                    }
+                    break;
+                case 'kemp-marina':
+                    $mainLevelPages[$page->ID] = $page->post_name;
+                    if ($pageCountIterator >= $vertLimit) {
+                        $last[] = $page->ID;
+                    }
+                    break;
+                case 'water-street-historic-block':
+                    $mainLevelPages[$page->ID] = $page->post_name;
+                    if ($pageCountIterator >= $vertLimit) {
+                        $last[] = $page->ID;
+                    }
+                    break;
+                }
+            }
+            ++$pageCountIterator;
+        }
+    }
     foreach ($pages as $page) {
         $classes = array();
-        if ($parent != 0) {
-            switch ($page->post_parent) {
-            case 5:
-                if (!$mainLevelPageCount[5]) {
+        if ($parent != 0 && isset($mainLevelPages[$parent])) {
+            switch ($mainLevelPages[$parent]) {
+            case 'museum-ship-valley-camp':
+                if (!$mainLevelPageCount[$parent]) {
                     echo '
                     <li class="nav_img-container"><a href="'.get_permalink($page->post_parent).'"><img src="'.get_bloginfo('template_url').'/assets/museum-drop-img.png"></a></li>
                     <li class="brief-d"><h3>Museum Ship Valley Camp</h3><a class="state">Explore an actual Great Lakes freighter!</a><p>The Museum Ship Valley Camp offers more than just a tour of her deck. Housed inside her massive cargo holds is a 20,000 square foot museum with over 100 exhibits!</p></li>
                     <li class="divde"><img src="'.get_bloginfo('template_url').'/assets/drop-rope.png"></li>
                         ';
-                    $mainLevelPageCount[5] = 1;
+                    $mainLevelPageCount[$parent] = 1;
                 }
                 break;
-            case 11:
-                if (!$mainLevelPageCount[11]) {
+            case 'tower-of-history':
+                if (!$mainLevelPageCount[$parent]) {
                     echo '
                     <li class="nav_img-container"><a href="'.get_permalink($page->post_parent).'"><img src="'.get_bloginfo('template_url').'/assets/tower-drop.png"></a></li>
                     <li class="brief-d"><h3>Tower of History</h3><p>Soaring 210 feet above Sault Ste. Marie and the Soo Locks, the tower has observation platforms for visitors to get spectacular views and photos of the world\'s busiest inland shipping channel.</p></li>
                     <li class="divde"><img src="'.get_bloginfo('template_url').'/assets/drop-rope.png"></li>
                         ';
-                    $mainLevelPageCount[11] = 1;
+                    $mainLevelPageCount[$parent] = 1;
                 }
                 break;
-            case 13:
-                if (!$mainLevelPageCount[13]) {
+            case 'river-of-history-museum':
+                if (!$mainLevelPageCount[$parent]) {
                     echo '
                     <li class="nav_img-container"><a href="'.get_permalink($page->post_parent).'"><img src="'.get_bloginfo('template_url').'/assets/river-drop.png"></a></li>
                     <li class="brief-d"><h3>River of History Museum</h3><p>The River of History Museum was opened by <a class="state">The Sault Ste. Marie Foundation for Culture and History</a> in 1992, with the mission of preserving and promoting the history of the St. Mary’s River system.</p></li>
                     <li class="divde"><img src="'.get_bloginfo('template_url').'/assets/drop-rope.png"></li>
                         ';
-                    $mainLevelPageCount[.5] = 1;
+                    $mainLevelPageCount[$parent] = 1;
                 }
                 break;
-            case 15:
-                if (!$mainLevelPageCount[15]) {
+            case 'kemp-marina':
+                if (!$mainLevelPageCount[$parent]) {
                     echo '
                     <li class="nav_img-container"><a href="'.get_permalink($page->post_parent).'"><img src="'.get_bloginfo('template_url').'/assets/kemp-drop.png"></a></li>
                     <li class="brief-d"><h3>Kemp Marina</h3><p>The George Kemp Downtown Marina boasts modern facilities within walking distance to downtown restaurants and attractions.</p></li>
                     <li class="divde"><img src="'.get_bloginfo('template_url').'/assets/drop-rope.png"></li>
                         ';
-                    $mainLevelPageCount[15] = 1;
+                    $mainLevelPageCount[$parent] = 1;
                 }
                 break;
-            case 17:
-                if (!$mainLevelPageCount[17]) {
+            case 'water-street-historic-block':
+                if (!$mainLevelPageCount[$parent]) {
                     echo '
                     <li class="nav_img-container"><a href="'.get_permalink($page->post_parent).'"><img src="'.get_bloginfo('template_url').'/assets/water-street-drop.png"></a></li>
                     <li class="brief-d"><h3>Water Street Historic Block</h3><p>The historic homes of the Historic Water Street Homes are operated through a cooperative effort between the Chippewa County Historical Society, the Sault Historic Sites, and the City of Sault Ste. Marie, Michigan. </p></li>
                     <li class="divde"><img src="'.get_bloginfo('template_url').'/assets/drop-rope.png"></li>
                         ';
-                    $mainLevelPageCount[17] = 1;
+                    $mainLevelPageCount[$parent] = 1;
                 }
                 break;
             }
@@ -126,11 +195,10 @@ function glm_page_menu($parent = 0, $class = '')
         echo "\n<li ";
         if ($totalCount > 0) {
             $classes[] = 'has-dropdown';
-            if (in_array($page->ID, array(5, 11, 13))) {
+            if (!in_array($page->ID, $last)) {
                 $classes[] = 'drop_left';
                 $classes[] = 'active';
-            }
-            if (in_array($page->ID, array(15, 17))) {
+            } else if (in_array($page->ID, $last)) {
                 $classes[] = 'drop_right';
                 $classes[] = 'active';
             }
@@ -139,20 +207,20 @@ function glm_page_menu($parent = 0, $class = '')
             echo 'class="'.implode(' ', $classes).'"'."\n";
         }
         if ($parent == 0) {
-            switch ($page->ID) {
-            case 5:
+            switch ($page->post_name) {
+            case 'museum-ship-valley-camp':
                 echo ' id="ship"';
                 break;
-            case 11:
+            case 'tower-of-history':
                 echo ' id="tower"';
                 break;
-            case 13:
+            case 'river-of-history-museum':
                 echo ' id="river"';
                 break;
-            case 15:
+            case 'kemp-marina':
                 echo ' id="marina"';
                 break;
-            case 17:
+            case 'water-street-historic-block':
                 echo ' id="street"';
                 break;
             }
diff --git a/theme.ini b/theme.ini
deleted file mode 100644 (file)
index b583183..0000000
--- a/theme.ini
+++ /dev/null
@@ -1,2 +0,0 @@
-[menu_options]
-main_level_pages = 5, 11, 13, 15, 17