Forums

[resolved] php code to list children of a known page (7 posts)

  1. robcub
    Member
    Posted 2 years ago #

    Hi,
    Does anybody know the code for listing the children of a page where you know the page's id?
    Cheers!

  2. buddha trance
    Member
    Posted 2 years ago #

  3. robcub
    Member
    Posted 2 years ago #

    Thank you, buddha trance, I'd been there. What I want is a list of all the children of a certain page. I actually want to list on page "Africa" it's children: "Angola" "Benin" "Botswana" etc.

    I might have missed something in that link.

  4. robcub
    Member
    Posted 2 years ago #

    I'm not there yet but I'm going a long way with this plugin:

    http://robm.me.uk/projects/plugins/wordpress/list-subpages

  5. buddha trance
    Member
    Posted 2 years ago #

    robcub, I just tested adding this to page.php of my theme, and it worked, displaying child pages on a parent page

    <ul>
      <?php
      wp_list_pages('title_li=&child_of='.$post->ID.''); ?>
      </ul>
  6. robcub
    Member
    Posted 2 years ago #

    Thank you, buddha trance, that's great. And if you want to display the child pages of a particular parent, say the page id is 5, you can do this on any page:

    <ul>
      <?php
      wp_list_pages('title_li=&child_of=5') ?>
    </ul>

    It wasn't me that worked that out.

    If you want to put either of these into the body of a page or post using Exec-PHP plugin, the code with the dynamically created post id doesn't work (it lists all pages and children) whereas the one with the specified page id does!

  7. samuraiwolfbrother
    Member
    Posted 2 years ago #

    Thank you all... I have been searching for something like this for hours...

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.