WordPress函数is_page()判断当前页面是否为“页面”

描述:

判断当前页面是否为“页面”

用法:

<?php is_page($page); ?>

参数:

$page

(mixed) (可选) 页面ID.标题或别名

默认值: None

示例:

is_page();
// When any single Page is being displayed.

is_page( 42 );
// When Page 42 (ID) is being displayed.

is_page( 'Contact' );
// When the Page with a post_title of "Contact" is being displayed.

is_page( 'about-me' );
// When the Page with a post_name (slug) of "about-me" is being displayed.

is_page( array( 42, 'about-me', 'Contact' ) );
// Returns true when the Pages displayed is either post ID 42, or post_name "about-me", or post_title "Contact".  Note: the array ability was added at Version 2.5.

源文件:

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Is the query for an existing single page?
 *
 * If the $page parameter is specified, this function will additionally
 * check if the query is for one of the pages specified.
 *
 * @see is_single()
 * @see is_singular()
 *
 * @since 1.5.0
 *
 * @global WP_Query $wp_query
 *
 * @param mixed $page Page ID, title, slug, or array of such.
 * @return bool
 */
function is_page( $page = '' ) {
	global $wp_query;

	if ( ! isset( $wp_query ) ) {
		_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
		return false;
	}

	return $wp_query->is_page( $page );
}