Created
January 15, 2010 10:10
-
-
Save whalesalad/277941 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| public static function primary_nav() { | |
| // The site-wide navigation | |
| // wp_list_pages(array('depth' => '1', 'title_li' => false)); | |
| $p = get_pages(array('parent' => 0, 'sort_column' => 'menu_order', 'hierarchical' => 0)); | |
| $pages = array(); | |
| global $wp_query; | |
| if (is_page() || is_attachment() || $wp_query->is_posts_page) | |
| $current_page = $wp_query->get_queried_object_id(); | |
| foreach ($p as $key => $page) { | |
| $css_class = array('page', 'page_item', 'page-item-'.$page->ID); | |
| // Handle the first link in the list | |
| if ($key == 0) | |
| $css_class[] = 'first'; | |
| // Handle the last link in the list | |
| if ($key == (count($p) - 1)) | |
| $css_class[] = 'last'; | |
| // If we're on the current page, simply make it active | |
| if ($page->ID == $current_page) | |
| $css_class[] = 'active'; | |
| // If we're on a sub page, make the parent page active. | |
| if (!empty($current_page)) { | |
| $_current_page = get_page($current_page); | |
| if (isset($_current_page->ancestors) && in_array($page->ID, (array) $_current_page->ancestors)) | |
| $css_class[] = 'active'; | |
| elseif ($_current_page && $page->ID == $_current_page->post_parent) | |
| $css_class[] = 'active'; | |
| } elseif ($page->ID == get_option('page_for_posts')) { | |
| $css_class[] = 'active'; | |
| } | |
| $pages[$key] = '<li class="'.implode(' ', $css_class).'"><a href="'.get_page_link($page->ID).'"><span>'.$page->post_title.'</span></a></li>'; | |
| } | |
| return implode("\n", $pages); | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment