描述
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;
- }