For some reason this will not work when I place it into my sidebar. I have copied it directly from the
CODEX. Does anyone have any suggestions? Thanks
As an alternative, this code in the sidebar.php, displays only top level Pages, but when viewing a Page that has children (or is a child) it displays only children of that parent.
When visiting main page, all top level pages are listed in the sidebar.
When visiting a top level page with no children, all top level pages are listed.
When visiting a top level page with children, just the children pages, and descendant pages, are listed.
When visiting a child page, just the children, and descendant pages, of that parent, are listed.
<ul role="navigation">
<?php
$output = wp_list_pages ( 'echo = 0 &depth = 1 &title_li = <h2> Top Level Pages </ h2>');
if (is_page ()) (
$page = $post-> ID;
if ($post-> post_parent) (
$page = $post-> post_parent;
)
$children = wp_list_pages ( 'echo = 0 &child_of ='. $page. '&title_li =');
if ($children) (
$output = wp_list_pages ( 'echo = 0 &child_of ='. $page. '&title_li = <h2> Child Pages </ h2>');
)
)
echo $output;?>
</ul>