| 2164 | | function get_page_hierarchy($posts, $parent = 0) { |
| 2165 | | $result = array ( ); |
| 2166 | | if ($posts) { foreach ( (array) $posts as $post) { |
| 2167 | | if ($post->post_parent == $parent) { |
| 2168 | | $result[$post->ID] = $post->post_name; |
| 2169 | | $children = get_page_hierarchy($posts, $post->ID); |
| 2170 | | $result += $children; //append $children to $result |
| 2171 | | } |
| 2172 | | } } |
| | 2167 | function &get_page_hierarchy( &$pages, $page_id = 0 ) { |
| | 2168 | |
| | 2169 | if ( empty( $pages ) ) |
| | 2170 | return null; |
| | 2171 | |
| | 2172 | $children = array(); |
| | 2173 | foreach ( (array) $pages as $p ) { |
| | 2174 | |
| | 2175 | $parent_id = intval( $p->post_parent ); |
| | 2176 | $children[ $parent_id ][] = $p; |
| | 2177 | } |
| | 2178 | |
| | 2179 | $result = array(); |
| | 2180 | _page_traverse_name( $page_id, $children, $result ); |
| | 2181 | |
| | 2186 | * function to traverse and return all the nested children post names of a root page. |
| | 2187 | * $children contains parent-chilren relations |
| | 2188 | * |
| | 2189 | */ |
| | 2190 | function _page_traverse_name( $page_id, &$children, &$result ){ |
| | 2191 | |
| | 2192 | if ( isset( $children[ $page_id ] ) ){ |
| | 2193 | |
| | 2194 | foreach( (array)$children[ $page_id ] as $child ) { |
| | 2195 | |
| | 2196 | $result[ $child->ID ] = $child->post_name; |
| | 2197 | _page_traverse_name( $child->ID, $children, $result ); |
| | 2198 | } |
| | 2199 | } |
| | 2200 | } |
| | 2201 | |
| | 2202 | /** |