get_post_ancestors()获取所有的父页面

目录

描述

Retrieve the parents of the post based on the post ID.

get_post_ancestors() 描述

用法

<?php get_post_ancestors$post ?>

get_post_ancestors() 用法

参数

$post

(mixed) (必填) Post ID or post object.

默认值: None

get_post_ancestors() 参数

返回值

(array) 

Array of IDs or empty if no ancestors are found. The direct parent is returned as the first value in the array. The highest level ancestor is returned as the last value in the array.

get_post_ancestors() 返回值

示例

Get Ancestors Page Slug

This example returns the highest page {slug} in a tree and uses it as a Body_Class, so the parent and all children will have the same Body Class!

This example for a twenty eleven child theme in the header.php file

Get Ancestors Post Meta

If we did not want to use the page slug, we could use a custom field eg: 'body_class', on the top level page and set the class in the post meta.

Get Ancestors Page Thumbnail

Get the top level page thumbnail and display it!

Adeptris

get_post_ancestors() 示例

历史

添加于 版本: 2.5.0

get_post_ancestors() 历史

源文件

get_post_ancestors() 函数的代码位于 wp-includes/post.php.

get_post_ancestors() 源文件