• 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;
    ?>
    \\

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hey Kadolf,

    I have no specific knowledge of the solution, but you may find it here if you haven’t come across an answer yet:

    https://www.tammyhartdesigns.com/tutorials/wordpress-how-to-list-child-pages-in-sidebar/

    This touches on the same general topic, and the last part of the post talks about putting a parent title on the top of a sidebar menu containing child pages.

    This is a bit ironic. When I posted the link for you, that wasn’t my issue, nor was your question the question I had. I was actually trying to solve a different problem that was somewhat related.

    However, after I solved my first problem, I realized my next issue was this exact same issue. So I came back here to get my own advice. ?? Ha.

    And, it worked. The parent title is now displayed on my child pages instead of the child title.

    The code from that link that worked is:

    <h3><?php
    $parent_title = get_the_title($post->post_parent);
    echo $parent_title;
    ?></h3>

    Here you can find a good working example of what you try to achieve.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display Parent title and children when on grandchild.’ is closed to new replies.