Child page within unordered list
-
Hi All
I’ve got some code that works to some extent, but I can’t quite get it right.
Basically, I’ve got an unordered list containing top level pages. If you are on a page that has children (sub pages), they should appear below in the unordered list. For example.
Here is my top-level menu:
Home
Services
Portfolio
About
ContactThe page ‘Services’ has a sub page, so when you are on the ‘Services’ page the menu should look like this:
Home
Services
Sub page of services
Portfolio
About
ContactMy code does this:
Home
Services
Portfolio
About
Contact
Sub page of servicesSo although I’m managing to get the sub page acknowledged by WP, it won’t show it under the parent page in the menu.
Here’s the code:
<ul><?php wp_list_pages('depth=1&title_li='); ?> <!-- This checks to see if the page being viewed is a parent of sub pages --> <?php global $wp_query; if( empty($wp_query->post->post_parent) ) { $parent = $wp_query->post->ID; } else { $parent = $wp_query->post->post_parent; } ?> <!-- This line runs if it is a parent --> <?php if(wp_list_pages("title_li=&child_of=$parent&echo=0" )): ?> <ul> <?php wp_list_pages("title_li=&child_of=$parent" ); ?> </ul> <?php endif; ?> </ul>
Although the HTML markup for the list seems correct, WP just sticks the sub page at the end of the unordered list a separate unordered list.
Help!
- The topic ‘Child page within unordered list’ is closed to new replies.