WordPress.org

Ready to get started?Download WordPress

Forums

Including the parent page in a list of subpages (6 posts)

  1. bizarrerie
    Member
    Posted 5 years ago #

    Currently, I am trying to get the link for the parent page to show in a list of its children.

    I am using this code:

    <?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>
      <?php echo $children; ?>
      </ul>
      <?php } ?>

    Which, works perfect. However, I want the parent page to show up in the ul as well. However, I DO NOT want an visual hierarchy. To be more precise this is how I wish the pages to display:

    Parent Page
    Child Page
    Child Page
    Child Page
    Child Page

    As opposed to:
    Parent Page
    -Child Page
    -Child Page
    -Child Page
    -Child Page

    Can anyone help me out? Thanks.

  2. Shane G
    Member
    Posted 5 years ago #

  3. bizarrerie
    Member
    Posted 5 years ago #

    I have read the codex pages. They are of no help to me.

    I would rather not use a plug-in.

    Any other solutions?

    Thanks

  4. hellomatt
    Member
    Posted 4 years ago #

    Hi, I'm not sure if you've resolved this issue but I was looking for the same thing and found a solution.

    Try 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) {
    $parent_title = get_the_title($post->post_parent);?>
    <li><a href="<?php echo get_permalink($post->post_parent) ?>"><?php echo $parent_title;?></a></li>
      <?php echo $children; ?>
      <?php } ?>

    If that doesn't work the way you want it to, let me know and I can probably help you some more.

  5. Morten Rand-Hendriksen
    Member
    Posted 4 years ago #

    Genius! Thanks hellomatt!

  6. schachandra
    Member
    Posted 4 years ago #

    THANK YOU! I spent hours looking for a solution, this works perfectly.

Topic Closed

This topic has been closed to new replies.

About this Topic