Bazujące na WordPress narzędzie wyszukiwania dla deweloperów i twórców motywów.



get_page_hierarchy ›

Od2.0.0
Przestarzałyn/a
get_page_hierarchy ( $pages, $page_id = 0 )
Parametry: (2)
  • (array) $pages Posts array (passed by reference).
    Wymagane: Tak
  • (int) $page_id Optional. Parent page ID. Default 0.
    Wymagane: Nie
    Domyślny:
Powrót:
  • (array) A list arranged by hierarchy. Children immediately follow their parents.
Zdefiniowane na:
Codex:

Order 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



Źródło

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

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

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

	return $result;
}