描述
wordpress根據頁面ID或對象返回頁面數據
使用
- <?php?get_page(?$page_id?)??>
參數
$page_id
(integer) (必須) Page ID 必須是 一個變量
默認: Page ID 使用的是全局變量
$output
(OBJECT/ARRAY_A/ARRAY_N) (可選) 輸出的類型.
默認: OBJECT
$filter
(string) (optional) 過濾的方式. 選項是 ‘raw’, ‘edit’, ‘db’, ‘display’, ‘attribute’ 和’js’. The ‘attribute’ and ‘js’ contexts are treated like ‘display’.
默認: ‘raw’
返回的值
- (object|array)
- mixed?Page?data.
- ???[ID]????????????????????=>?(integer)
- ???[post_author]???????????=>?(integer)
- ???[post_date]?????????????=>?(YYYY-MM-DD?HH:MM:SS)
- ???[post_date_gmt]?????????=>?(YYYY-MM-DD?HH:MM:SS)
- ???[post_content]??????????=>?(all?post?content?is?in?here)
- ???[post_title]????????????=>?(Post?Title?Here)
- ???[post_excerpt]??????????=>?(Post?Excerpt)
- ???[post_status]???????????=>?(??|?publish)
- ???[comment_status]????????=>?(??|?closed)
- ???[ping_status]???????????=>?(??|?closed)
- ???[post_password]?????????=>?(blank?if?not?specified)
- ???[post_name]?????????????=>?(slug-is-here)
- ???[to_ping]???????????????=>?(?)
- ???[pinged]????????????????=>?(?)
- ???[post_modified]?????????=>?(YYYY-MM-DD?HH:MM:SS)
- ???[post_modified_gmt]?????=>?(YYYY-MM-DD?HH:MM:SS)
- ???[post_content_filtered]?=>?(?)
- ???[post_parent]???????????=>?(integer)
- ???[guid]??????????????????=>?(a?unique?identifier?that?is?not?necessarily?the?URL?to?the?Page)
- ???[menu_order]????????????=>?(integer)
- ???[post_type]?????????????=>?(??|?page)
- ???[post_mime_type]????????=>?()?)
- ???[comment_count]?????????=>?(integer)
- ???[ancestors]?????????????=>?(object|array)
- ???[filter]????????????????=>?(??|?raw)
如果你要獲取頁面的URL,不要使用guid字段值。使用the_permalink或者get_permalink 代替。
如果頁面不存在,返回null
示例
- <?php
- $page_id?=?123;
- $page_data?=?get_page(?$page_id?);
- echo?'<h3>'.?$page_data->post_title?.'</h3>';
- echo?apply_filters('the_content',?$page_data->post_content);?
- ?>
源文件
get_page() 位于wp-includes/post.php.
- function?&get_page(&$page,?$output?=?OBJECT,?$filter?=?'raw')?{
- ?$p?=?get_post($page,?$output,?$filter);
- ?return?$p;
- }