php - List page menu with children and grandchildren in wordpress -
okay it's been on year since made wordpress theme , i've started again i've run problem menu on pages.
this current page hierarchy (i'm still testing hence names)
home page *child 1 **grandchild 1 **grandchild 2 *child 2 **grandchild 3 **grandchild 4 **grandchild 5 *child 3 **grandchild 6 page
now when visit "this page" want show link "this page" (current) , direct childs (no grandchildren here) of "this page" in sketch: http://img840.imageshack.us/img840/3006/thispage.png
now when visit "child 1" of "this page" want show above menu , childs of "child 1" (grandchild 1 & 2) in sub ul under "child 1" in sketch: http://img4.imageshack.us/img4/7868/child1.png
and when visit "grandchild 1" want show same menu did "child 1" "grandchild 1" current item instead in sketch: http://img819.imageshack.us/img819/1633/grandchild1.png
this current code based on example in wordpress codex (under wp_list_pages() function) other type of menu isn't working , absolutely not godchildren.
<?php if($post->post_parent){ $children = wp_list_pages("title_li=&include=".$post->post_parent."&echo=0"); $children .= wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); } else{ $children = wp_list_pages("title_li=&child_of=".$post->id."&echo=0"); } if ($children) { ?> <div class="page-menu"> <ul> <?php echo $children; ?> </ul> </div> <?php } ?>
my plan have menu sidebar on page can see in sketches.
so know how 1 achieve result?
i recommend using wp_list_pages()
, , bring in css hide parts don't want visible (there plenty of classes outputted function, check source see what's available).
in addition, you're going make lot easier search engines (and users, if they're using limited browser or accessibility enhancement) browse site, since entire hierarchy there in html.
Comments
Post a Comment