List child pages of a specific page

I’m looking for a snippit/function that will list the child pages of a specific page (I guess by page ID) but not necessarily when you are on that page or a child of that page. The parent page (Parents Area) and its child pages are listed below:

Parents Area
- Term Dates
- Calendar
- School Blog
- Letters to Parents
- Attendance

I want to be able to be on any page of the website, specifically within single posts and post archives but be able to list out just the children of the parent page “Parents Area”.

Related posts

2 comments

  1. To list subpages of a particular page, use wp_list_pages with child_of argument.

    $parent_page_id = 42;
    wp_list_pages( array(
        'child_of' => $parent_page_id
    ) );
    
  2. Maybe I didn’t quite get what was asked for, but what’s wrong in using wp_list_pages?

    Here is a sample code (which most probably has to be customized and adapted to fit your needs):

    <ul>
        <?php
        $args = array(
            'depth' => 1,
            'include' => YOUR PAGE ID HERE,
            'title_li' => '',
        );
        wp_list_pages($args);
        $args['child_of'] = $args['include'];
        unset($args['include']);
        wp_list_pages($args);
        ?>
    </ul>
    

    Maybe you have to adapt the HTML list as well, if you want a hierarchical list of two levels etc.

Comments are closed.