From: Steve Sutton Date: Fri, 3 Apr 2015 15:04:04 +0000 (-0400) Subject: Work on menu X-Git-Tag: v1.0.0^2~25 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=3ac7e316a6f795e011f64473b41b427e78b0fd76;p=WP-Themes%2FSaultHistoricSites.git Work on menu 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. --- diff --git a/functions.php b/functions.php index 49e68f1..271f1e1 100644 --- a/functions.php +++ b/functions.php @@ -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 ''."\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 '
  • Museum Ship Valley Camp

    Explore an actual Great Lakes freighter!

    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!

  • '; - $mainLevelPageCount[5] = 1; + $mainLevelPageCount[$parent] = 1; } break; - case 11: - if (!$mainLevelPageCount[11]) { + case 'tower-of-history': + if (!$mainLevelPageCount[$parent]) { echo '
  • Tower of History

    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.

  • '; - $mainLevelPageCount[11] = 1; + $mainLevelPageCount[$parent] = 1; } break; - case 13: - if (!$mainLevelPageCount[13]) { + case 'river-of-history-museum': + if (!$mainLevelPageCount[$parent]) { echo '
  • River of History Museum

    The River of History Museum was opened by The Sault Ste. Marie Foundation for Culture and History in 1992, with the mission of preserving and promoting the history of the St. Mary’s River system.

  • '; - $mainLevelPageCount[.5] = 1; + $mainLevelPageCount[$parent] = 1; } break; - case 15: - if (!$mainLevelPageCount[15]) { + case 'kemp-marina': + if (!$mainLevelPageCount[$parent]) { echo '
  • Kemp Marina

    The George Kemp Downtown Marina boasts modern facilities within walking distance to downtown restaurants and attractions.

  • '; - $mainLevelPageCount[15] = 1; + $mainLevelPageCount[$parent] = 1; } break; - case 17: - if (!$mainLevelPageCount[17]) { + case 'water-street-historic-block': + if (!$mainLevelPageCount[$parent]) { echo '
  • Water Street Historic Block

    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.

  • '; - $mainLevelPageCount[17] = 1; + $mainLevelPageCount[$parent] = 1; } break; } @@ -126,11 +195,10 @@ function glm_page_menu($parent = 0, $class = '') echo "\n
  • 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 index b583183..0000000 --- a/theme.ini +++ /dev/null @@ -1,2 +0,0 @@ -[menu_options] -main_level_pages = 5, 11, 13, 15, 17