Advertisements

get_page_hierarchy

Definition:
function &get_page_hierarchy( &$pages, $page_id = 0 ) {}

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

Parameters

  • array $pages: Posts array.
  • int $page_id: Parent page ID.
  • &$pages

Return values

returns:A list arranged by hierarchy. Children immediately follow their parents.

Source code

function &get_page_hierarchy( &$pages, $page_id = 0 ) {

	if ( empty( $pages ) ) {

		$result = array();

		return $result;

	}



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

}

1536

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: