Changeset 11976
- Timestamp:
- 09/26/2009 10:45:52 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/post.php
r11968 r11976 2156 2156 * Order the pages with children under parents in a flat list. 2157 2157 * 2158 * It uses auxiliary structure to hold parent-children relationships and 2159 * runs in O(N) complexity 2160 * 2158 2161 * @since 2.0.0 2159 2162 * … … 2162 2165 * @return array A list arranged by hierarchy. Children immediately follow their parents. 2163 2166 */ 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 2173 2182 return $result; 2183 } 2184 2185 /** 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 } 2174 2200 } 2175 2201
Note: See TracChangeset
for help on using the changeset viewer.