Template Files
Read previously that template files holds the information for our theme template.
There are various types of template files.
- Post template files
- Page template files
- Attachment Template Files
- Custom Post Type template files
- Partial and Misc template files
- Taxonomy template files
- 404 files
List of files for all the category are as follows
Post template files
- index.php
- home.php
- single.php
- singular.php
- archive.php
- author.php & date.php
- category.php, tag.php, taxonomy.php
- search.php
Page Template Files
- page-{slug}.php
- page-{id}.php
- page.php
- singular.php
- index.php
Attachment Template Files
- MIME_type.php || subtype.php
Mime type -> image.php, video.php
Sub type -> text/plain -> text_plain.php,plain.php, text.php
Converter from text/plain to text_plain - attachment.php
- single-attachment.php
- single.php
- singular.php
- index.php
Custom Post Type template files
- single-{post-type}.php
single-mlb_movie.php -> else single.php - archive-{post-type}.php
archive-mlb_movie.php -> else archive.php - index.php -> fallback if none of the above or search.php is not found
Partial and Misc template files
- header.php -> contain header data, good idea to add wp_head() here -> call via get_header()
- footer.php -> contains footer data, add wp_footer() here -> call via get_footer()
- 404.php -> if 404.php is not defined, it would fallback to index.php if a 404 error comes up
- comments.php
- sidebar.php
- content-{$slug}.php
Used via get_template_part() -> to get content on the basis of types, fallback -> content.php
Taxonomy template files
For taxonomy
- taxonomy-{taxonomy}-{term}.php
- taxonomy-{taxonomy}.php
- tag-{slug}.php
- tag-{id}.php
For categories
- category-{slug}.php
- category-{ID}.php
Conditional Tags
WordPress provides us various tags to use to check for conditions.
We cannot use conditional tags in functions.php as the conditional tags can only run after the query is executed, and functions.php is run before the query is executed.
- is_user_logged_in() -> tells if the current visitor is logged in
- is_home() -> if currently on the main page
- is_front_page() -> the main page of the blog is displayed, even if it is a static page
- is_single() -> if single post is being displayed
- is_singular() -> if single post/page/attachment is being disaplyed
- is_sticky() -> if the post is a sticky post
- get_post_type() -> will tell us the post type for the current post
- is_page() -> returns if a page is being displayed
- check if it is a subpage -> if post_parent is set in post object
- is_page_template() -> if a page template is being used
- is_category() -> is it the category archive?
- is_tag() -> is it a tag archive?
- is_tax() -> is it taxonomy archive?
- is_author() -> is it author archive?
- is_date() -> is it the date archive?
- is_archive() -> is it any type of archive?
- is_search() -> is the current result related to search?
- is_404() -> is it the 404 error?
Checking user browser
Also with the help of the global variables wordpress provides us
$is_lynx
$is_gecko
$is_winIE
$is_macIE
$is_opera
$is_NS4
$is_safari
$is_chrome
$is_iphone
$is_edgeCode :
$browser = 'undefined';
if ( $is_chrome ) {
$browser = 'Chrome';
} elseif ( $is_gecko ) {
$browser = 'Firefox';
} elseif ( $is_IE ) {
$browser = 'Internet explorer';
} elseif ( $is_safari ) {
$browser = 'Safari';
} elseif ( $is_opera ) {
$browser = 'Opera';
} else {
$browser = 'Unknown';
}
printf( 'The current browser is %s', $browser );