4

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".

7
  • Post your code please.
    – s_ha_dum
    Sep 12, 2013 at 15:08
  • 1
    The code for which part? I don't have any code for this functionality just yet. I've got my code (functions.php) to output my subnav across the rest of the site which works perfectly: pastebin.com/HKeyqjXE I need to do exactly the same thing, but for a specified page ID regardless of what page I'm on.
    – lotech
    Sep 13, 2013 at 13:32
  • As written, I can't help but consider this "work for me for free". You are expected to have researched the problem and made an attempt at solving it before posting a question. There are a lot of "list child pages" questions to the right under "RELATED". Why don't you try to get yourself started and edit the question so that it addresses some more specific problem that you encounter.
    – s_ha_dum
    Sep 13, 2013 at 13:43
  • 1
    That's OK, I understand. I'm just not sure where to start on this one. Am I best off amending my code above, or is this a rather long way of doing it just for this task?
    – lotech
    Sep 13, 2013 at 14:01
  • 1
    OK, I've updated my original post to provide a more accurate description of the problem.
    – lotech
    Sep 13, 2013 at 15:21

2 Answers 2

3

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
) );
1
  • 1
    Awesome, that was all I needed! Sorry, still learning my way around the WP functions.
    – lotech
    Sep 13, 2013 at 17:24
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.