/ Published in: PHP
This was for a customer.
Basically it does this:
If a page has no children, it shows ... nothing,
if a page has a parent, it shows all other children of this parent (siblings) and the current page
if a page has a parent AND children (3rd level), it shows two separate menus, one with the siblings and current page and one with the children of the third level.
Maybe it helps someone.
Basically it does this:
If a page has no children, it shows ... nothing,
if a page has a parent, it shows all other children of this parent (siblings) and the current page
if a page has a parent AND children (3rd level), it shows two separate menus, one with the siblings and current page and one with the children of the third level.
Maybe it helps someone.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php //Automatic Submenu global $wp_query; //If current page has no parent... { echo ""; } else //current page has parents { $me=$wp_query->post->ID; $children = wp_list_pages("title_li=&child_of=$me&echo=0"); if ($children) { $parent1 = $wp_query->post->post_parent; //show menu with current page's siblings echo "<ul class='submenus'>"; wp_list_pages("title_li=&child_of=$parent1&depth=1"); echo "</ul>"; $parent2 = $wp_query->post->ID; //show menu with current page's children echo "<ul class='subsubmenu'>"; wp_list_pages("title_li=&child_of=$parent2&depth=1"); echo "</ul>"; } else { $parent1 = $wp_query->post->post_parent; //show ONLY menu with current page's siblings echo "<ul class='submenus'>"; wp_list_pages("title_li=&child_of=$parent1&depth=1"); echo "</ul>"; } } ?>