get_page_uri()
get_page_uri( WP_Post|object|int $page )
为页生成URI路径。
Build the URI path for a page.
说明(Description)
子页将位于父页文章名下的“目录”中。
参数(Parameters)
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
$page | (WP_Post | object | int) | 可选 | 页面ID或WP_Post对象。默认值为全局$post。 |
返回(Return)
(string|false)页URI,错误时为false。
源码(Source)
/** * 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; }
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
4.6.0 | wp-includes/post.php:5162 | 4 | 3 |
笔记(Notes)
例子
get_page_uri() 为WP2原创文章,链接:https://www.wp2.cn/functions/get_page_uri/