【描述】
根据页面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 ); //必须传递个变量. 如果传递值 (e.g. get_page ( 123 ); ), WordPress会报错. 默认将会返回一个对象. echo '<h3>'. $page_data->post_title .'</h3>';// 输出标题 echo apply_filters('the_content', $page_data->post_content); //输出内容 ?>
【源文件】
get_page() 位于wp-includes/post.php.
/** * Retrieves page data given a page ID or page object. * * @since 1.5.1 * * @param mixed $page Page object or page ID. Passed by reference. * @param string $output What to output. OBJECT, ARRAY_A, or ARRAY_N. * @param string $filter How the return value should be filtered. * @return mixed Page data. */ function &get_page(&$page, $output = OBJECT, $filter = 'raw') { $p = get_post($page, $output, $filter); return $p; }