Posted By

zartgesotten on 11/19/10


Tagged

menu pages wordpress navigation subpages functionsphp siblings


Versions (?)

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


 / Published in: PHP
 

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

Works!

  1. add_filter('wp_list_pages_excludes', 'remove_others_children');
  2. function remove_others_children($excludes = array()) {
  3. $all_pages = get_pages();
  4. $all_children = (array) get_page_children(true, $all_pages);
  5. foreach ( $all_children as $child )
  6. $excludes[] = $child->ID;
  7.  
  8. if ( ! is_page() )
  9. return $excludes;
  10.  
  11. global $post;
  12.  
  13. $this_heirarchy = (array) $post->ancestors;
  14. $this_children = (array) get_page_children($post->ID, $all_pages);
  15. foreach ( $this_heirarchy as $ancestor )
  16. $this_children = array_merge($this_children, (array) get_page_children($ancestor, $all_pages));
  17.  
  18. foreach ($this_children as $child)
  19. $this_heirarchy[] = $child->ID;
  20.  
  21. return array_diff($excludes, $this_heirarchy);
  22. }

Report this snippet  

You need to login to post a comment.