WordPress Conditional Tags

- URL : WordPress.org | Codex : https://codex.wordpress.org/Conditional_Tags

- boolean 타입, 즉 true 혹은 false를 반환



The Main Page : is_home()


The Front Page : is_front_page()


The Blog Page : is_front_page() and is_home()

if ( is_front_page() && is_home() ) {
  // Default homepage
} elseif ( is_front_page() ) {
  // static homepage
} elseif ( is_home() ) {
  // blog page
} else {
  //everything else
}


A Single Post Page :

is_single() : When a single post of any post type (except attachment and page post types) is being displayed.

is_single( '17' ) : When Post 17 is being displayed as a single Post.

is_single( 'Irish Stew' ) : When the Post with Title "Irish Stew" is being displayed as a single Post.

is_single( 'beef-stew' ) : When the Post with Post Slug "beef-stew" is being displayed as a single Post.


A Sticky Post : is_sticky()


A Post Type Archive : is_post_type_archive()


A PAGE Page :

This section refers to WordPress Pages, not any generic web page from your blog, or in other words to the built in post_type 'page'.

이 섹션은 WordPress 페이지를 말하며 블로그의 일반적인 웹 페이지가 아닙니다. 즉, 내장된 post_type '페이지'를 말합니다 .

is_page() : When any Page is being displayed.

is_page( 42 ) : When Page 42 (ID) is being displayed.

if ($board_id == '1' && is_page(42)) {
	$mode = 'editor';
}

is_page( 'About Me And Joe' ) : When the Page with a post_title of "About Me And Joe" 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', 'About Me And Joe' ) ) : Returns true when the Pages displayed is either post ID = 42, or post_name is "about-me", or post_title is "About Me And Joe".

is_page( array( 42, 54, 6 ) ) : Returns true when the Pages displayed is either post ID = 42, or post ID = 54, or post ID = 6.


 ※ See also is_page() for more snippets, such as is_subpage, is_tree.

 ※ Note: There is no function to check if a page is a sub-page. We can get around the problem :

if ( is_page() && $post->post_parent > 0 ) { 
    echo "This is a child page";
}


Is a Page Template :
Allows you to determine whether or not you are in a page template or if a specific page template is being used.

is_page_template() : Is a Page Template being used?

is_page_template( 'about.php' ) : Is Page Template 'about' being used?


A Category Page :

is_category( $category ) : When the actual page is associated with the $category Category.

is_category( '9' ) : When the archive page for Category 9 is being displayed.

is_category( 'Stinky Cheeses' ) : When the archive page for the Category with Name "Stinky Cheeses" is being displayed.

is_category( 'blue-cheese' ) : When the archive page for the Category with Category Slug "blue-cheese" is being displayed.

Posted by cpu21