wordpress通过页面的路径获取页面信息
$page_path
(string) (必须) 页面路径
Default: None
$output
(string) (可选) 输出类型. OBJECT, ARRAY_N, or ARRAY_A.
Default: OBJECT
$post_type
(string) (可选) 文章类型.
Default: page
(mixed)
Null when complete.
这个等价于通过 ‘pagename’ 来查找, 类似: ‘index.php?pagename=parent-page/sub-page’.
Code for the above could be written as (assuming ‘parent-page/sub-page’ is actually the path to a page):
For non-heirarchical custom post types, you need to use just the slug in tandem with the post_type parameter.
//Returns nothing, assumes animals is the rewrite slug for the animal CPT
//Returns the animal with the slug ‘cat’
The functions basename() and untrailingslashit() are handy for grabbing the last part of the URL for this:
$page_path = ‘animals/cat/’;
get_page_by_path() 位于wp-includes/post.php.
主题猫WP建站,累计帮助1300+客户成功建站,为站长提供支持!
立刻开启你的建站之旅