is_page

Sponsored Link

この条件タグは、ページが表示されている場合にチェックします。これは、プール関数で、TRUE か FALSEのいずれかを返すという意味です。このタグは、ループ前に使用する必要があり、ループ内では動作しません(以下の注を参照)。

Sponsored Link

This Conditional Tag checks if Pages are being displayed. This is a boolean function, meaning it returns either TRUE or FALSE. This tag must be used BEFORE The Loop and does not work inside The Loop (see Notes below).

is_pageのファンクションタグ使用方法

<?php is_page($page); ?>

is_pageのパラメーター

$page

(mixed) (optional) ページID,ページタイトル、ページスラッグ。
デフォルト:なし

(mixed) (optional) Page ID, Page Title or Page Slug
Default: None

戻り値

(boolean)
失敗した場合にFALSE、成功時にはtrue。

(boolean)
true on success, false on failure.

is_page();
// 任意のシングルページが表示されているとき。When any single Page is being displayed.

is_page(42);
// ページ42(ID)が表示されている時。When Page 42 (ID) is being displayed.

is_page('Contact');
// "Contact"のpost_titleページが表示されている時。When the Page with a post_title of "Contact" is being displayed.

is_page('about-me');
// "about-me"のpost_name(スラッグ)が表示されている時。When the Page with a post_name (slug) of "about-me" is being displayed.

is_page(array(42,'about-me','Contact'));
// ページが投稿IDが42、post_nameが"about-me"、post_titleが"Contact"のいずれかが表示されている時trueを返します。注:配列機能はバージョン2.5で追加されました。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.

注釈

空の値を渡すと、TRUEを返します。

次の行でtrueが返されるので、特定のページをチェックするためのパラメーターとしての空の値を渡す可能性がある場合は細心の注意を払ってください。

Be very careful if there’s a possibility of passing an empty value as a parameter to check for a specific page, since the following lines will return true:

is_page( '' )
is_page( 0 )
is_page( '0' )
is_page( null )
is_page( false )
is_page( array() )
  • 参照: is_singular()

ループ内では使用できません

ループ中に上書きされる特定のグローバル変数のため、 is_page()は動作しません。ループ後それを使用するためには、ループ後にwp_query_reset()を呼び出す必要があります。

Due to certain global variables being overwritten during The Loop is_page() will not work. In order to use it after The Loop you must call wp_query_reset() after The Loop.

  • is_page_template()を参照してください。

変更ログ

Since: 1.5.0

ソースファイル

is_page()は、wp-includes/query.php内に位置しています。

is_page() is located in wp-includes/query.php.

関連ファンクションタグ

Conditional Tags: comments_open(), is_404(), is_admin(), is_archive(), is_attachment(), is_author(), is_category(), is_comments_popup(), is_date(), is_day(), is_feed(), is_front_page(), is_home(), is_local_attachment(), is_multi_author, is_month(), is_new_day(), is_page(), is_page_template(), is_paged(), is plugin active(), is_plugin_page(), is_post_type_archive(), is_preview(), is_search(), is_single(), is_singular(), is_sticky(), is_tag(), is_tax(), is_taxonomy_hierarchical(), is_time(), is_trackback(), is_year(), in_category(), in_the_loop(), is_active_sidebar(), is_active_widget(), is_blog_installed(), is_rtl(), is_dynamic_sidebar(), is_user_logged_in(), has_excerpt(), has_post_thumbnail(), has_tag(), pings_open(), email exists(), post_type_exists(), taxonomy_exists(), term_exists(), username exists()

Sponsored Link