WordPress 1.3 introduces the “is” series of template functions. These tell you what type of page is being requested. For example, is_home() is true if the home page is being requested. is_category() is true if a category is being requested. Here is the full list of “is” functions and the requests for which they are true.
- is_home() – The front page
- is_single() – A single post
- is_page() – A static/standalone page
- is_category() – A category
- is_author() – An author
- is_date() – A year, month, or day
- is_year() – A year
- is_month() – A month
- is_day() – A day
- is_time() – An hour, minute, or second
- is_archive() – A category, author, or date
- is_search() – A search
- is_404() – A 404 page
- is_feed() – A syndication feed
Further, is_single(), is_page(), is_category(), and is_author() can accept an id, name, or nicename. Here are some examples using is_page().
- is_page() – True if a page is being served.
- is_page(3) – True if a page with the ID of 3 is being served.
- is_page(‘About Me’) – True if the page title is ‘About Me’.
- is_page(‘about-me’) – True if the page nicename is ‘about-me’.
The “is” functions are very handy for customising your template for different query types. One index.php template can provide a different look for each query type using the “is” functions. Simply use the “is” functions to form conditionals for the various request types and generate whatever markup you like for each of those conditionals.
The presence of many conditionals can make the template rather busy and difficult to read, however. An alternative is to use multiple templates. If a single post is being requested and a file named single.php is present, that will be loaded instead of the index. The same is true for categories, authors, pages, and so on. If is_category() is true and category.php is present, category.php is loaded. For each “is” function, strip the “is_” from the front and append “.php” to derive the name of the template that will be loaded if that “is” function evaluates to true. Providing multiple templates is completely optional, of course. If you would like to continue using index.php for everything, go right ahead.
The “is” functions and the query-to-template mapping provide template and theme designers a great deal of control over presentation, whether it be through one template or multiple templates. For an example of how to use the “is” functions and the template mapping to build a theme, look to the Kubrick theme.