WordPress.org

Ready to get started?Download WordPress

Forums

Page & Sub-Page Exclusion From 'wp_list_pages' (3 posts)

  1. OldBoyGLA
    Member
    Posted 4 years ago #

    Hi guys. I'm developing a wordpress blog for use as a CMS for a client and I'm having a little trouble with navigation.

    Right now, I have a manually coded navigation but I would like to utilise the wp_list_pages function in order to provide an easier to manage navigation.

    Looking at past topics on this board, there have been a few posts asking how to exclude pages from wp_list_pages based on page title. For example,

    <?php
    $page1 = get_page_by_title ('Client Area');
    $page2 = get_page_by_title ('Services');
    $page3 = get_page_by_title ('Galleries');
    
    wp_list_pages('sort_column=menu_order&exclude=' . $page1->ID . ',' . $page2->ID . ',' . $page3->ID . '&title_li=');
    ?>

    However, I was wondering if there was any way to write this in a similar way so that when it excludes a parent page, it also excludes all child pages of that page?

    For example, If a page called "Services" had two sub-pages called "Weddings" and "Events", when I excluded "Services" it automatically excludes all child pages.

    Thanks for your time,
    OB.

  2. richard.calahan
    Member
    Posted 4 years ago #

    Use the exclude_tree parameter. Add to your code:

    wp_list_pages('sort_column=menu_order&title_li=&exclude_tree=5');

    This code will exclude the parent and children of a page with an ID of 5.

  3. OldBoyGLA
    Member
    Posted 4 years ago #

    Your a legend. Thank you very much mate.

Topic Closed

This topic has been closed to new replies.

About this Topic