WordPress function: determine the type of page, such as home page, article page, search page

WordPress is composed of home page, article page, search page and 404 page. When you want to show, hide, replace and load some content on a special page, you need to use page judgment function to judge. For example, in the article page and only when some content is displayed in the article page, you can use the function is_single() judgment.

WordPress has rich built-in page judgment functions. The output of the judgment functions listed below is true under any conditions. In addition, these functions can accept parameters.

Administrator panel judgment function

is_admin() / / returns true when the control panel or administrator panel is displayed

Home page judgment function

is_home() / / determine whether it is the home page, and the display is not a static page

is_front_ page () / / judge whether it is the home page, including static page and dynamic page

is_home()&&!is_ paged() / / determine the first page of the first page

Article and page judgment function

is_single () / / is it an article page

is_single ('17 ') / / when the article with ID 17 is displayed separately

is_single ('wan Ge Ji Ba ') / / when the article titled "Wan Ge Ji Ba" is displayed separately

is_single ('chong Zi Jun ') / / when the article alias "Chong Zi Jun" is displayed separately

is_single (array (23, 'Chong Zi Jun','wan Ge Ji Ba ') / / when the article ID is 23, or the alias is' Chong Zi Jun', or the title is' Wan Ge Ji Ba ', it returns ture.

is_sticky () / / is it the top article

is_sticky ('2019 ') / / when an article with ID 2019 is placed at the top, return to ture.

is_page() / / is it a page

is_page ('18 ') / / when the page with ID 18 is displayed separately

is_page ('wan Ge Ji Ba ') / / when the page titled "Wan Ge Ji Ba" is displayed separately

is_page ('chong Zi Jun ') / / when the page alias "Chong Zi Jun" is displayed separately

is_page (array (42, 'Chong Zi Jun','wan Ge Ji Ba ')) / / when the page ID is 42, or the alias is "Chong Zi Jun", or the title is "Wan Ge Ji Ba", it returns ture.

is_single() / / whether it is an article page, page or attachment, equivalent to is_single()||is_ page()||is_ attachment()

comments_ open() / / allow comments. Note that there is no is in the front_

pings_open() / / whether Ping is allowed. Note that there is no is in the front_

Classification catalog archiving judgment function

is_category() / / is it a category

is_category ('9 ') / / when the category ID is 9, it is displayed separately

is_category ('wan Ge Ji Ba ') / / when the category titled "Wan Ge Ji Ba" is displayed separately

is_category ('chong Zi Jun ') / / when the category directory with alias "Chong Zi Jun" is displayed separately

is_category (array (9, 'Chong Zi Jun','wan Ge Ji Ba ')) / / when the category ID is 9, or the alias is' Chong Zi Jun', or the title is' Wan Ge Ji Ba ', return ture.

is_category()&&!is_ Page () to judge the first page of the first page of the classification

in_category ('5 ') / / attention! If the specified category ID of the current post is 5, it will return true.

Label archiving judgment function

is_tag() / / is it a label archive page

is_tag ('biao Qian Yi ') / / when the tag is displayed as Biao Qian Yi

is_tag (array ('biao Qian Yi ','biao Qian Er','biao Qian San ') / / when the tag is any one of Biao Qian Yi, Biao Qian Er, Biao Qian SAN)

has_tag() / / when the article contains Tags

has_tag ('biao Qian Yi ') / / when an article contains a Biao Qian Yi tag

has_tag (array ('biao Qian Yi ','biao Qian Er','biao Qian San ') / / when the article contains any tag of Biao Qian Yi, Biao Qian Er, Biao Qian San

Author's judgment function

is_author() / / archive page for author

is_author ('4 ') / / when the author ID is 4 and displayed separately

is_author ('vivian ') / / when the author's user name is Vivian, it is displayed separately

is_author ('john Jones') / / when the author's nickname is John Jones, it is displayed separately

is_author (array (4, 'John Jones','vivian')) returns ture when author ID is 4, user name is Vivian or nickname is John Jones

Time archive judgment function

is_date() / / determine whether to archive the date page

is_year() / / determine whether to archive the page in the year

is_month() / / judge whether to archive the page monthly

is_day() / / determine whether to archive the page daily

is_time() //When an hourly, "minutely", or "secondly" archive is being displayed.

Other judgment functions

is_archive() / / determines whether to archive the page

is_search() / / determine whether it is a search page

is_tag() / / judge whether to select a tab

is_404 () / / determine whether or not the page is 404

is_paged() / / determines whether pages are paged, which means when the home page or archive is divided into several pages

is_attachment() / / determine whether it is an attachment page

is_feed() / / determine whether it is in the feed

is_preview() / / when viewing a single post in draft mode

has_excerpt() / / judge whether there is a summary

has_excerpt('42') //

in_ the_ loop() / / check if it is in the loop. Useful for plug-in authors, this condition returns true when in a loop

is_ active_ sidebar() / / checks whether the given sidebar is active (in use). If the sidebar is used (identified by name, ID or number), it returns true; otherwise, it returns false

Examples of usage

<?php
//If it is an article page or a single page
if ( is_ single () || is_ page()) {
//Write the function to be executed or the content to be displayed here
}
?>

Original article, author: brian, if reprinted, please indicate the source:https://www.nicebrian.com/26.html

Leave a Reply

Your email address will not be published. Required fields are marked *