Created
March 6, 2012 08:59
-
-
Save stefanledin/1985021 to your computer and use it in GitHub Desktop.
Wordpress-meny i tre nivåer
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
| <!-- | |
| Fungerar på denna typ av menysystem: | |
| Huvudmeny => Drycker | |
| Undermeny => Cocacola | |
| Tredjemeny => Smaker | |
| --> | |
| <!DOCTYPE html> | |
| <html lang="sv"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>Undermeny i 3 nivåer</title> | |
| <style> | |
| /** | |
| * Visar undermenyn på rätt sidor | |
| */ | |
| .submenu li.current_page_item ul.children, .submenu li.current_page_ancestor ul.children { | |
| display: block; | |
| } | |
| /** | |
| * Döljer undermenyn | |
| */ | |
| ul.children { | |
| margin-left: 15px; | |
| display: none; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <nav class="submenu"> | |
| <?php | |
| /** | |
| * if (!empty($post->ancestors[1])) | |
| * --- | |
| * Om du klickat på "Smaker" | |
| * | |
| * ===================================================== | |
| * | |
| * elseif($post->post_parent !== $post->ancestors[0]) | |
| * -- | |
| * Om du klickat på "Drycker" | |
| * | |
| * ===================================================== | |
| * | |
| * else | |
| * -- | |
| * Om du klickat på "Cocacola" | |
| */ | |
| if (empty($post->ancestors[2]) && isset($post->ancestors[1])) { | |
| $ancestor = get_page($post->ancestors[1]); | |
| $subpage = '<ul><li class="submenu-header"><a href="'.$ancestor->guid.'">'.$ancestor->post_title.'</a></li>' . wp_list_pages('title_li=&child_of='.$post->ancestors[1].'&echo=0') . '</ul>'; | |
| } elseif(!empty($post->ancestors[2])) { | |
| $ancestor = get_page($post->ancestors[2]); | |
| $subpage = '<ul><li class="submenu-header"><a href="'.$ancestor->guid.'">'.$ancestor->post_title.'</a></li>' . wp_list_pages('title_li=&child_of='.$post->ancestors[2].'&echo=0') . '</ul>'; | |
| } elseif($post->post_parent !== $post->ancestors[0]) { | |
| $page = get_page($post->ID); | |
| $subpage = '<ul><li class="submenu-header"><a href="' . $page->guid . '">' . $page->post_title .'</a></li>' . wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0') . '</ul>'; | |
| } else { | |
| $parent = get_page($post->post_parent); | |
| $subpage = '<ul><li class="submenu-header"><a href="' . $parent->guid .'">' . $parent->post_title . '</a></li>' . wp_list_pages('title_li=&child_of='.$post->post_parent.'&echo=0') . '</ul>'; | |
| } | |
| echo $subpage; | |
| ?> | |
| </nav> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment