WordPress函数get_page_uri()通过页面id获取别名

描述:

通过页面id获取别名

用法:

<?php get_page_uri( $page_id ) ?>

参数:

$page_id

(integer) (必填) 页面ID.

默认值: None

示例:

<?php
$page_id = 5;
$uri = get_page_uri($page_id);
echo '<a href="'. $uri .'">The Page</a>';
?>

源文件:

/**
 * Build URI for a page.
 *
 * Sub pages will be in the "directory" under the parent page post name.
 *
 * @since 1.5.0
 *
 * @param WP_Post|object|int $page Page object or page ID.
 * @return string|false Page URI, false on error.
 */
function get_page_uri( $page ) {
	$page = get_post( $page );

	if ( ! $page )
		return false;

	$uri = $page->post_name;

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

	return $uri;
}