WordPress.org

Support

Support » How-To and Troubleshooting » How to exclude child_of from wp_list_pages?

How to exclude child_of from wp_list_pages?

  • Hi there,
    Is there a simple way to exclude child_of=134 from the wp_list_pages?
    He is is my wp_list_pages code…

    $pages = wp_list_pages('sort_column=menu_order&title_li=&echo=0&depth=3&exclude='.$exclude);

    I need to exclude all child of 134 page, but not the 134 page itself.
    Is this possible?
    Thank you 🙂

Viewing 7 replies - 1 through 7 (of 7 total)
  • Steve

    @stevielovegun

    You can use the Exclude Pages plugin to exclude the individual child pages via a checkbox in the edit page screen.

    This still doesn’t do exactly what you need but it’s a good plugin for page by page control of what appears in menus.

    Thanks Stevie!
    That’s nice but I need to setup this in order the editors of the website don’t have to worry about this exclude pages in the future. I need a definite solution… any ideas?

    The template tag, wp_list_pages(), has an exclude_tree argument you might consider.

    thank you Michael!
    yess i saw that… but i need to exclude only the child (and new child will be created by the editors) not the parent, how to do it?

    <?php
    $child_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE $wpdb->posts.post_parent = 134  AND $wpdb->posts.post_type = 'page' AND $wpdb->posts.post_status = 'publish' ORDER BY $wpdb->posts.ID ASC");
    $exclude = implode($child_ids,', ');
    wp_list_pages('exclude=' . $exclude . '&title_li=<h2>' . __('Pages') . '</h2>');
    ?>

    Could you just exclude it from the list_pages command and add it to the end seperately, or does it have to appear in order?

    <ul>
    wp_list_pages ('sort_column=menu_order&title_li=&echo=0&depth=3&exclude=134');
    wp_list_pages ('sort_column=menu_order&title_li=&echo=0&depth=1&include=134');
    </ul>

    Not sure if that is what you need.

    MichaelH,

    I have the following:

    global $wpdb;
    
    $child_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE $wpdb->posts.post_parent = 18  AND $wpdb->posts.post_type = 'page' AND $wpdb->posts.post_status = 'publish' ORDER BY $wpdb->posts.ID ASC");
    
    $exclude = implode($child_ids,', ');
    
    wp_list_pages('exclude=' . $exclude . '&sort_column=menu_order&title_li=');

    And as a result I get the expected list of links, followed by an unexpected list of the excluded pages. What am I doing wrong?

    Thx in advance!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to exclude child_of from wp_list_pages?’ is closed to new replies.