get_page_hierarchy() - WordPress 函数参考中文文档

返回介绍

get_page_hierarchy()

发布于 2017-09-10 字数2215 浏览 778 评论 0

get_page_hierarchy( array $pages,  int $page_id )

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


参数

$pages

(array)
(Required)
Posts array, passed by reference.

$page_id

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


返回值

(array) A list arranged by hierarchy. Children immediately follow their parents.


源代码

File: wp-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 = intval( $p->post_parent );
		$children[ $parent_id ][] = $p;
	}

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

	return $result;
}

更新日志

Version 描述
2.0.0 Introduced.

相关函数

Uses

  • wp-includes/post.php:
    _page_traverse_name()

Used By

  • wp-includes/class-wp-rewrite.php:
    WP_Rewrite::page_uri_index()

User Contributed Notes

  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note

    Contributed by jonradio

    get_page_hierarchy() returns an ID=>page_title array: the Key is ID of a Page, and the Value is the Page’s Title.

    The Title is not modified by indentation or other means to indicate a Child Page immediately below its Parent Page.

上一篇:get_page_children()

下一篇:get_page_link()

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!