Retrieves page data given a page ID or page object.

Pages provide a way to have static content that will not affect things like articles or archives or any other blog entry features of WordPress. Its simply a way to turn a blog entry into static content.

get_page() 描述


<?php get_page$page_id ?>

get_page() 用法



(integer) (必填) Page ID passed by reference (see example below)

默认值: Page ID from global variable at time function is called


(OBJECT/ARRAY_A/ARRAY_N) (可选) What to output.



(string) (可选) How the return value should be filtered. Options are 'raw', 'edit', 'db', 'display', 'attribute' and 'js'. The 'attribute' and 'js' contexts are treated like 'display'.

默认值: 'raw'

get_page() 参数



mixed Page data.

/* ----------------------------------
 * wordpress之魂 ©
 * ---------------------------------- */
   [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)

If you need the URL to the Page, don't try and use the guid value. Use the_permalink or get_permalink instead.

If a page is not found, a null value is returned.

This page is marked as incomplete. You can help Codex by expanding it.

get_page() 返回值


This example code can be used when you want to include the text of a specific page in a theme.

/* ----------------------------------
 * wordpress之魂 ©
 * ---------------------------------- */

$page_id = 123; // 123 should be replaced with a specific Page's id from your site, which you can find by mousing over the link to edit that Page on the Manage Pages admin page. The id will be embedded in the query string of the URL, e.g. page.php?action=edit&post=123.

$page_data = get_page( $page_id ); // You must pass in a variable to the get_page function. If you pass in a value (e.g. get_page ( 123 ); ), WordPress will generate an error. By default, this will return an object.

echo '<h3>'. $page_data->post_title .'</h3>';// echo the title

echo apply_filters('the_content', $page_data->post_content); // echo the content and retain WordPress filters such as paragraph tags.

get_page() 示例


  • Deprecated: 3.5.0
  • 添加于 版本: 1.5.1

get_page() 历史


get_page() 函数的代码位于

/* ----------------------------------
 * wordpress之魂 ©
 * ---------------------------------- */
 * Retrieves page data given a page ID or page object.
 * Use get_post() instead of get_page().
 * @since 1.5.1
 * @deprecated 3.5.0 Use get_post()
 * @param mixed  $page   Page object or page ID. Passed by reference.
 * @param string $output Optional. What to output. Accepts OBJECT, ARRAY_A, or ARRAY_N.
 *                       Default OBJECT.
 * @param string $filter Optional. How the return value should be filtered. Accepts 'raw',
 *                       'edit', 'db', 'display'. Default 'raw'.
 * @return WP_Post|array|null WP_Post on success or null on failure.
function get_page( $page, $output = OBJECT, $filter = 'raw') {
	return get_post( $page, $output, $filter );

get_page() 源文件