WordPress.org

Ready to get started?Download WordPress

Forums

How to exclude child_of from wp_list_pages? (8 posts)

  1. guigo3k
    Member
    Posted 4 years ago #

    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 :)

  2. Steve
    Member
    Posted 4 years ago #

    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.

  3. guigo3k
    Member
    Posted 4 years ago #

    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?

  4. MichaelH
    Member
    Posted 4 years ago #

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

  5. guigo3k
    Member
    Posted 4 years ago #

    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?

  6. MichaelH
    Member
    Posted 4 years ago #

    <?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>');
    ?>
  7. nathan12343
    Member
    Posted 4 years ago #

    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.

  8. jkd77
    Member
    Posted 4 years ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Topic