get_page_hierarchy()

最后更新于:2021-11-26 11:02:25

get_page_hierarchy( GC_Post[]$pages, int$page_id)

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

参数

$pages

(GC_Post[]) (Required) Posts array (passed by reference).

$page_id

(int) (Optional) Parent page ID. Default 0.

响应

(string[]) Array of post names keyed by ID and arranged by hierarchy. Children immediately follow their parents.

源文件

文件: gc-includes/post.php

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;
}