views:

183

answers:

0

Does anyone know how to achieve a dynamic multi-level page menu for Wordpress? I have found a couple scripts but none of them put the subpages directly under the parent page or some will show every subpage to the entire menu

Example:

page1 (selected)
–subpage1-1
–subpage1-2
page2
page3

This code comes close by inserting the subpages directly under, but it doesn't hide the subpages to the other pages.

<?php
if($post->post_parent) {
$children = preg_replace('@\<li([^>^]*)>\<a([^>^]*)>(.*?)\<\/a>@i','<li$1><a$2><span>$3</span></a>',wp_list_pages('title_li=&amp;amp;amp;amp;amp;child_of='.$post->post_parent.'&amp;amp;amp;amp;amp;echo=0&amp;amp;amp;amp;amp;depth=1'));
} else {
$children = preg_replace('@\<li([^>^]*)>\<a([^>^]*)>(.*?)\<\/a>@i','<li$1><a$2><span>$3</span></a>',wp_list_pages('title_li=&amp;amp;amp;amp;amp;child_of='.$post->ID.'&amp;amp;amp;amp;amp;echo=0&amp;amp;amp;amp;amp;depth=1'));
}
if($children) {
echo"
<ul class=\"submenu\">\n".
$children
."</ul>\n";
} ?>