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


/ Published in: PHP
Save to your folder(s)

Works!


Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.