php 获得WordPress帖子中最顶级的父母

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 获得WordPress帖子中最顶级的父母相关的知识,希望对你有一定的参考价值。

/**
 * Gets the top most ancestor for a post.
 * 
 * @param  object		$post		The current post
 * 
 * @return integer	       	The post ID of the ancestor
 */
function get_top_ancestor( $post ) {
	if ( $post->post_parent )	{
		$ancestors = get_post_ancestors( $post->ID );
		$root = count( $ancestors ) - 1;
		$parent = $ancestors[$root];
	} else {
		$parent = $post->ID;
	}
	return $parent;
}

以上是关于php 获得WordPress帖子中最顶级的父母的主要内容,如果未能解决你的问题,请参考以下文章