Display Parent title and children when on grandchild.
-
Hello,
I’m very new to this, but trying to cut my teeth. I’m using this code from the codex in my sidebar and I can’t figure out how to display the parent title instead of this <h2>Child Pages</h2>Essentially I would like my sidebar, when on any specific area in my site, to display the parent title as a title/header and then list all the children and grandchildren as sublinks. This almost gets me there except for the parent title part – and the fact that when I’m on a grandchild page it no longer displays the children (it would be great to do that too). Any help is greatly appreciated. Thanks!
\\
<?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;
?>
\\
- The topic ‘Display Parent title and children when on grandchild.’ is closed to new replies.