Skip to main content
We are Brand SEO Beijing serving international business, your marketing partner, Contact us by mi@mgsh.com.cn

Website CMS custom theme file structure

Before you start making a WordPress website theme, you must first understand what files the WordPress website theme consists of, and you need to know how the WordPress website program is connected to the theme files.Generally speaking, a theme needs to contain at least two files: index.php and style.css.
In detail, the files that may exist are:
Home:

  1. home.php
  2. index.php (this is a panacea)
Article page:
  1. single-{post_type}.php – If the post type is videos (ie videos), WordPress will look for single-videos.php (supported by WordPress 3.0 and above)
  2. single.php
  3. index.php

page:

  1. xxx.php (optional file name), custom page template – when creating a page in the WordPress backend, you can select a custom template for the page in the right sidebar
  2. page-{slug}.php – if the abbreviated name of the page is news, WordPress will look for page-news.php (supported in WordPress 2.9 and above)
  3. page-{id}.php – if the page ID is 6, WordPress will look for page-6.php
  4. page.php
  5. index.php

Category Template:

  1. category-{slug}.php – If the category is short for news, WordPress will look for category-news.php (supported in WordPress 2.9 and above)
  2. archive-{post_type}.php – if your theme has a custom post type, for example, according to the official website tutorial, registered a post type named book, then its archive page template is category-book.php, if there is no this file, it will not be replaced with other files, it will go straight to 404
  3. taxonomy-{taxonomy_slug}.php - This is the classification page of the custom taxonomy. For example, above you register the article type of a book, and then you register a taxonomy author, whose alias is authors, so that articles can be classified by author.Then the template file for this author classification page is taxonomy-authors.php
  4. category-{id}.php - if the category id is 6, WordPress will look for category-6.php
  5. category.php
  6. archive.php
  7. index.php

TAG

  1. tag-{slug}.php – if the tag is abbreviated as sometag, WordPress will look for tag-sometag.php
  2. tag-{id}.php – if the tag ID is 6, WordPress will look for tag-6.php (supported in WordPress 2.9 and above)
  3. tag.php
  4. archive.php
  5. index.php

作者:

  1. author-{nicename}.php – If the author’s nickname is rami, WordPress will look for author-rami.php (supported in WordPress 3.0 and above)
  2. author-{id}.php – If the author ID is 6, WordPress will look for author-6.php (supported in WordPress 3.0 and above)
  3. author.php
  4. archive.php
  5. index.php

Date page:

  1. date.php
  2. archive.php
  3. index.php

search results:

  1. search.php
  2. index.php

404 (Not Found) page

  1. 404.php
  2. index.php

Attachment page:

  1. MIME_type.php - can be any MIME type (image.php, video.php, audio.php, application.php or whatever).
  2. attachment.php
  3. single.php
  4. index.php

function

  1. functions.php

Comment template

  1. comments.php

Regarding the file hierarchy above
In addition to the above custom article types, and custom taxonomies require a fixed template to display the corresponding content, other files can be replaced by other files if the corresponding files are missing.Take the home page as an example, there are 2 files belowhome.phpindex.php.WordPressThe program will look for these two files in turn from your theme folder, if foundhome.php, then usehome.phpas a blog homepage template, even if you haveindex.php;in casehome.phpnot found, useindex.phpas a homepage template; ifhome.phpindex.phpare not found, your theme will not beWordPressRecognition equals waste.
For so many files above, not all of them need to be prepared, and what template is needed to use. For more complex themes, there are usually many php functions. In order to have a clear hierarchical structure, the author will usually package the code in other php files. , you can include files in functions.php using functions such as include_once.
Reprinted from: WordPress theme making tutorial www.ashuwp.com

Back to Top