function to list parent and child page (2 posts)

  1. Lori
    Posted 4 years ago #

    I have seen several questions about this on the forum, but couldn't find any that have been answered.

    In my header.php I would like to add a navigation link to a parent page and its children. But I can't find a way to do this simply with a function (so it will automatically update when new child pages are added). I've done it with "include" like this:

    <?php wp_list_pages('title_li=&include=1357,1368&depth=2'); ?>

    1357 is the parent, and 1368 is the child.

    But I don't want to have to manually edit my header file every time I add a new child page. Of course, I could use "exclude" and add all the pages that I DON'T want to show up, but that also means manual editing every time I add a page. Ugh.

    Is there a simple way to to list a parent and its children (for navigation) with a function? So sorry if I've missed this in the codex, but wp_page_menu doesn't seem to do the trick either.


  2. vtxyzzy
    Posted 4 years ago #

    If you want the children of the current page, this might work:

    <?php if ($id = $posts[0]->ID)
       wp_list_pages("title_li=&child_of=$id&depth=2"); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic