WordPress.org

Ready to get started?Download WordPress

Forums

Displaying Parent Page on Child Page (3 posts)

  1. dcprime
    Member
    Posted 6 years ago #

    Hey everyone!

    I'm just new to the forums, and I have a quick (and hopefully easy) question.

    I have a site that has several parent pages, with several child pages under each. When I click on a child page, I would like the name of the parent page and the child page to each be displayed at the top of the page (instead of just the current page name, as it does now).

    I'm sure there must be some piece of PHP code that I can insert to do this, but I'm still very early in the learning process when it comes to PHP. Can anyone offer a suggestion?

  2. impresslab
    Member
    Posted 5 years ago #

    I need this too!

    I have as my page order:

    Home Page
    - Food
    - Sports
    - - Football
    - - Soccer
    - Cars
    - About Us

    When I visit the "Food Page" i see a all Food, Sports (w/children), Cars, and About. When I visit Football, I only see Football.

  3. jakilevy
    Member
    Posted 5 years ago #

    You can take a look at this page:
    http://codex.wordpress.org/Customizing_Your_Sidebar#Different_Sidebars_Anyone.3F

    The code below will list all the child pages.

    So if you're using impresslab's site, and you're on Sports -> Football , this code will list Football, Soccer

    <?php // LIST ALL CHILD PAGES
      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>
      <?php echo $children; ?>
      </ul>

Topic Closed

This topic has been closed to new replies.

About this Topic