When a visitor clicks on a hyperlink to category, tag or custom taxonomy, WordPress displays a page of posts in reverse chronological order filtered by that taxonomy.
By default, this page is generated using the index.php template file. You can create optional template files to override and refine the index.php template files. This section explains how to use and create such templates.
WordPress display posts in the order determined by the Template Hierarchy.
The category.php, tag.php, and taxonomy.php templates allow posts filtered by taxonomy to be treated differently from unfiltered posts or posts filtered by a different taxonomy. (Note: post refers to any post type – posts, pages, custom post types, etc.). These files let you target specific taxonomies or specific taxonomy terms. For example:
- taxonomy-{taxonomy}-{term}.php
- taxonomy-{taxonomy}.php
- tag-{slug}.php
- tag-{id}.php
- category-{slug}.php
- category-{ID}.php
So you could format all posts in an animal taxonomy named news on a page that looks different from posts filtered in other categories.
The archive.php template provides the most general form of control, providing a layout for all archives; that is, a page that displays a list of posts.
For categories, WordPress looks for the category-{slug}.php file. If it doesn’t exist, WordPress then looks for a file for the next hierarchical level, category-{ID}.php, and so on. If WordPress fails to find any specialized templates or an archive.php template file, it reverts to the default behavior, using index.php.
The category hierarchy is listed below:
- category-{slug}.php: For example, if the category’s slug is named “news,” WordPress would look for a file named category-news.php.
- category-{ID}.php: For example, if the category’s ID is “6”, WordPress would look for a file named category-6.php.
- category.php
- archive.php
- index.php
Read more »