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+客戶成功建站,為站長提供支持!
立刻開啟你的建站之旅