wpseek.com
Un motore di ricerca WordPress per sviluppatori e autori di temi



get_page_hierarchy › WordPress Function

Da2.0.0
Deprecaton/a
get_page_hierarchy ( $pages, $page_id = 0 )
Parametri: (2)
  • (WP_Post[]) $pages Posts array (passed by reference).
    Richiesto:
  • (int) $page_id Optional. Parent page ID. Default 0.
    Richiesto: No
    Default:
Ritorna:
  • (string[]) Array of post names keyed by ID and arranged by hierarchy. Children immediately follow their parents.
Definito a:
Codex:

Orders the pages with children under parents in a flat list.

It uses auxiliary structure to hold parent-children relationships and runs in O(N) complexity


Sorgenti

function get_page_hierarchy( &$pages, $page_id = 0 ) {
	if ( empty( $pages ) ) {
		return array();
	}

	$children = array();
	foreach ( (array) $pages as $p ) {
		$parent_id                = (int) $p->post_parent;
		$children[ $parent_id ][] = $p;
	}

	$result = array();
	_page_traverse_name( $page_id, $children, $result );

	return $result;
}