Exclude pages in a section (exclude_tree)

All you have to do is include this block of code in your template the same way you would the regular <?php wp_list_pages();?> tag. Page IDs that you would normally pass to exclude_tree go in the first line):

<?php $parent_pages_to_exclude = array(31,33,18,74);
foreach($parent_pages_to_exclude as $parent_page_to_exclude) {
if ($page_exclusions) { $page_exclusions .= ',' . $parent_page_to_exclude; }
  else { $page_exclusions = $parent_page_to_exclude; }
  $descendants = get_pages('child_of=' . $parent_page_to_exclude);
  foreach($descendants as $descendant) {
    $page_exclusions .= ',' . $descendant->ID;
  }
}
wp_list_pages('title_li=&sort_column=menu_order&exclude=' . $page_exclusions); ?>

Revisions

There are no revisions for this post.

Tags: , ,

No comments yet.

Leave a Reply