• Hi all,

    Apologies if this is covered elsewhere. I’ve searched all over but can’t find an answer.

    I’m building a site which relies heavily on 1.5’s page functionality. I’d like to use pages and sub-pages almost like categories. So, if I have a page called “Colours”, I’d like to be able to have a box on that page that links to the page’s sub-pages e.g. “red, yellow, green” and so on.

    I know that wp_list_pages lets me exclude certain pages, but I’d rather include pages, than have to update my template to exclude pages each time.

    To sum up: I’d like to write a bit of PHP, in a template, that looks at what the page is (or what a sub-page’s parent page is) and displays links to all the associated sub-pages.

    Any advice?

    Thanks!

    Matthew.

Viewing 3 replies - 1 through 3 (of 3 total)
  • I am a php ignoramus but I have been striving to implement Pages on my own site and have gone over the relevant parts of the Codex with a fine-tooth comb. Perhaps I don’t understand what you are trying to do, but wouldn’t the child_of argument for wp_list_pages be suited for what you want to do?

    I’m doing something similar on my site, but I’m listing child pages as part of the text of the parent page. I’ve done this with a combination of the PHP Exec plugin and WordPress template tags within the page, like this:

    <ul><phpcode>
    <?php wp_list_pages('sort_column=menu_order&child_of=1&title_li='); ?>
    </phpcode></ul>

    You could use a similar technique with the wp_list_page tag to accomplish your desired effect in the template, with logic to provide the value of “child_of” in the tag query.

    The wp_list_pages tag with the child_of argument set to the id of the page whose children you want to display will do the job you describe, but will not display any page outside of that subset of pages.

    Depending on how you want to set things up, that may be what you are looking for,

    An alternative would be to display the page list in a way that collapses all pages other than the current one, and this can be done with the Fold Page List plugin, designed as a replacement for wp_list_pages.

    Might be worth a try

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Pages: display link to page and its sub-pages only’ is closed to new replies.