Return to Snippet

Revision: 36164
at November 19, 2010 00:39 by zartgesotten


Initial Code
add_filter('wp_list_pages_excludes', 'remove_others_children');
function remove_others_children($excludes = array()) {
  $all_pages = get_pages();
  $all_children = (array) get_page_children(true, $all_pages);
  foreach ( $all_children as $child )
    $excludes[] = $child->ID;

  if ( ! is_page() )
    return $excludes;

  global $post;

  $this_heirarchy = (array) $post->ancestors;
  $this_children = (array) get_page_children($post->ID, $all_pages);
  foreach ( $this_heirarchy as $ancestor )
    $this_children = array_merge($this_children, (array) get_page_children($ancestor, $all_pages));

  foreach ($this_children as $child)
    $this_heirarchy[] = $child->ID;

  return array_diff($excludes, $this_heirarchy);
}

Initial URL
http://www.firesidemedia.net/dev/show-only-children-pages-on-parent-page/

Initial Description
Works!

Initial Title
wordpress functions.php - Show only current page's subpages and current pages siblings, hide sibling's subpages

Initial Tags
wordpress, navigation

Initial Language
PHP