/ Published in: PHP

This small snippet can be used to get the children and grand children of a Wordpress page. See the comments for how it works
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* $grandma = the ancestor to check it with $include can be used to include grandma herself too please pay attention that the GetChildren is calling itself recursively use it like: $family = $this->GetFamilyTree($id, true) or $family = $this->GetFamilyTree($id, false) when you don't want grandma herself too see: http://codex.wordpress.org/Function_Reference/get_children for additional info author: J.J. van de Merwe, Enovision GmbH */ function GetFamilyTree($grandma = 1, $include = true) { if ($include) { } $this->GetChildren($grandma, $family); return $this->family; } private function GetChildren($id) { 'post_parent' => $id, 'post_type' => 'page', 'numberposts' => -1, 'post_status' => 'publish' )); foreach ($members as $member) { $this->GetChildren($member->ID); } }
Comments
