wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



get_page_children › WordPress Function

Seit1.5.1
Veraltetn/v
get_page_children ( $page_id, $pages )
Parameter: (2)
  • (int) $page_id Page ID.
    Erforderlich: Ja
  • (WP_Post[]) $pages List of page objects from which descendants should be identified.
    Erforderlich: Ja
Gibt zurück:
  • (WP_Post[]) List of page children.
Definiert in:
Codex:

Identifies descendants of a given page ID in a list of page objects.

Descendants are identified from the $pages array passed to the function. No database queries are performed.


Quellcode

function get_page_children( $page_id, $pages ) {
	// Build a hash of ID -> children.
	$children = array();
	foreach ( (array) $pages as $page ) {
		$children[ (int) $page->post_parent ][] = $page;
	}

	$page_list = array();

	// Start the search by looking at immediate children.
	if ( isset( $children[ $page_id ] ) ) {
		// Always start at the end of the stack in order to preserve original `$pages` order.
		$to_look = array_reverse( $children[ $page_id ] );

		while ( $to_look ) {
			$p           = array_pop( $to_look );
			$page_list[] = $p;
			if ( isset( $children[ $p->ID ] ) ) {
				foreach ( array_reverse( $children[ $p->ID ] ) as $child ) {
					// Append to the `$to_look` stack to descend the tree.
					$to_look[] = $child;
				}
			}
		}
	}

	return $page_list;
}