WordPress.org

Ready to get started?Download WordPress

Forums

list_pages - include X with subpages possible? (3 posts)

  1. Janzomaster
    Member
    Posted 6 years ago #

    Hi, I'm trying to set up some kind of archive page and wanted to make a list of pages on that page as well.

    I created a page template with wp_list_pages in it. Now I want to display a list of not all pages but only some.

    Now neither exclude nor include really does what I want.
    I can't exclude all the ones that won't fit, as that wouldn't exclude newly created pages, thus being to undynamic.

    And when I include my archives-page, the subpages arent displayed in the list, and that was kind of the goal here - by just adding some old posts to the archive parent page as subpages, thus making them archived.
    Is there somekind of workaround to force list_pages to display subpages of an included parent page even though these pages arent included themselves?

    My god I dont think I could have expressed in a more complicated way. Hoping for help...

  2. Janzomaster
    Member
    Posted 6 years ago #

    I could really use some help.

  3. MichaelH
    Member
    Posted 6 years ago #

    With my test data, I have page id 5 as the parent page. This code finds that page and all pages that have that page as a parent (they are children of page 5)

    <?php
    $parent = '5'
    $all_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE ID = " .$parent. " OR post_parent =" .$parent. " ORDER BY post_parent");
    $page_ids = implode(",", $all_ids);
    $wlp_param_list='depth=0&include=' . $page_ids;
    wp_list_pages($wlp_param_list);
    ?>

    I used this code in a Page template.

Topic Closed

This topic has been closed to new replies.

About this Topic