Dynamic vertical menu for Wordpress

Posted by buttonstack on Stack Overflow See other posts from Stack Overflow or by buttonstack
Published on 2010-05-22T01:12:55Z Indexed on 2010/05/22 1:20 UTC
Read the original article Hit count: 245

Filed under:
|
|
|
|

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";
} ?>

© Stack Overflow or respective owner

Related posts about Wordpress

Related posts about dynamic