• This is the first time I’m posting so excuse me if I don’t get it right ??

    the page/section in question
    https://atyantcapital.com.s42598.gridserver.com/about/

    1. on the left hand side, note that the top level page “About Us” is listed and below that, the child pages of the “About Us” page.
    2. Now click on one of the child pages.
    3. Note that the name of the current child page now appears where the words “about us” used to be
    4. What I want is for the name of the parent page to always appear, now matter what child page the user is on.

    Here is the code:

    <?php if(!is_home() and !is_search() and !is_single()) {
    /* For non-blog pages */ ?>
      <?php
    
    echo "<h4>";wp_title('');echo "</h4>";
    if($post->post_parent)
    $children = wp_list_pages("sort_column=menu_order&depth=2&title_li=&child_of=".$post->post_parent."&echo=0"); else $children = wp_list_pages("sort_column=menu_order&depth=2&title_li=&child_of=".$post->ID."&echo=0");
    if ($children) { ?>
    <ul>
    <?php echo $children; ?>
    </ul>
    <?php } ?>
    <?php } ?>

    So wp_title is obviously outputting the current page, even if it’s a child page. What I need is the magic key to make the output there only be the name of a parent page.

    If anyone can help, I’ll be eternally grateful. I spent time going thru the codex and the support forum but this is the one time I wasn’t able to find an answer.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Yes, wp_title will always output the title of the current page, not matter what it’s level. I am not aware of any magic way to do that through WordPress.

    You might need to use a custom template for each set of child pages with a static <h4> of whatever you want the title to be on all the pages and don’t include wp_title. That, or an if statement to dictate the title to the child pages.

    Try with this:

    <?php if(!is_home() and !is_search() and !is_single()) {
    /* For non-blog pages */ ?>
      <?php
    if ($post->post_parent) {
    echo "<h4>.get_the_title($post->ID);echo "</h4>";
    } else {
    echo "<h4>";wp_title('');echo "</h4>";
    }
    if($post->post_parent)
    $children = wp_list_pages("sort_column=menu_order&depth=2&title_li=&child_of=".$post->post_parent."&echo=0"); else $children = wp_list_pages("sort_column=menu_order&depth=2&title_li=&child_of=".$post->ID."&echo=0");
    if ($children) { ?>
    <ul>
    <?php echo $children; ?>
    </ul>
    <?php } ?>
    <?php } ?>

    oops, small error in my previous post:

    <?php if(!is_home() and !is_search() and !is_single()) {
    /* For non-blog pages */ ?>
      <?php
    if ($post->post_parent) {
    echo "<h4>.get_the_title($post->post_parent);echo "</h4>";
    } else {
    echo "<h4>";wp_title('');echo "</h4>";
    }
    if($post->post_parent)
    $children = wp_list_pages("sort_column=menu_order&depth=2&title_li=&child_of=".$post->post_parent."&echo=0"); else $children = wp_list_pages("sort_column=menu_order&depth=2&title_li=&child_of=".$post->ID."&echo=0");
    if ($children) { ?>
    <ul>
    <?php echo $children; ?>
    </ul>
    <?php } ?>
    <?php } ?>
    Thread Starter lhutt

    (@lhutt)

    Thanks for the help AliciaW and carlosmendoza.

    Carlos, I tried your suggestion and while it technically is pulling in the correct parent page ID, it is not outputting the actual parent name – only the function and ID.

    But I see where you are going with this. You are looking for the parent page with the .get_the_title ($post->post_parent) function and then outputting that info.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘trouble outputting current page title ONLY if it is the parent page’ is closed to new replies.