• Ok, I think thi might be very easy but I am new to php, so here goes.

    I have set up a sidebar to show only a list of related child pages and parent. I have links to the parents at the top of the page as tabs and the side bar changes according to the tab I select. Here is how I did the sidebar:

    <?php
    if($post->post_parent)
    $children = wp_list_pages(“sort_column=menu_order&title_li=&child_of=”.$post->post_parent.”&echo=0″); else
    $children = wp_list_pages(“sort_column=menu_order&title_li=&child_of=”.$post->ID.”&echo=0″);
    if ($children) { ?>

      <?php echo $children; ?>

    <?php } ?>

    This worked like a charm, but I also want to add the parent title to appear as the title of the list on the sidebar. I think I could change the “title_li=” and add some kind of parameter after the “=” where this will call for the name of the parent page, but I don’t know what that parameter is. Does anyone have any ideas?????

    Thank you very much

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter juankrlz

    (@juankrlz)

    Anyone??????? Please!

    I’m looking to do the exact same thing!!

    i’m also wondering how to do this…

    Can anyone provide any help on this? I have the same issue. My header has the main nav with just parents, then in the page template I include the sidebar which is just a simple submenu with children. It looks like this:

    <?php
    if($post->post_parent)
    $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) { ?>
    <ul id="submenu">
      <?php echo $children; ?>
    </ul>
    <?php } ?>

    I would like my output to be something like this:

    <h2>NAME OF PARENT PAGE HERE</h2>
    <ul id="submenu">
      <li>Name of Child 1</li>
      <li>Name of Child 2</li>
      <li>...etc</li>
    </ul>

    So, I’m just missing the h2, which should be the NAME of the PARENT page. Any help would be MUCH appreciated.

    this worked for me in displaying the current page’s parent as the title:

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

    Put this between your h2 tags

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Post parent page as a title for all the child pages on sidebar .’ is closed to new replies.