get_page_uri()

最后更新于:2021-11-26 11:17:27

get_page_uri( GC_Post|object|int$page)

Build the URI path for a page.

参数

$page

(GC_Post|object|int) (Optional) Page ID or GC_Post object. Default is global $post.

响应

(string|false) Page URI, false on error.

源文件

文件: gc-includes/post.php

function get_page_uri( $page = 0 ) {
	if ( ! $page instanceof GC_Post ) {
		$page = get_post( $page );
	}

	if ( ! $page ) {
		return false;
	}

	$uri = $page->post_name;

	foreach ( $page->ancestors as $parent ) {
		$parent = get_post( $parent );
		if ( $parent && $parent->post_name ) {
			$uri = $parent->post_name . '/' . $uri;
		}
	}

	/**
	 * Filters the URI for a page.
	 *
	 * @since 4.4.0
	 *
	 * @param string  $uri  Page URI.
	 * @param GC_Post $page Page object.
	 */
	return apply_filters( 'get_page_uri', $uri, $page );
}