一个WordPress主题都有那些文件,及它们之间的层级关系是怎样的?
比如文章详情页,single-{post-type}-{slug}.php 文件优先级最高,其次是single-{post-type}.php文件->single.php->singular.php->index.php。优先级高的文件会覆盖优先级低的文件。
单页
1. custom template file
2. page-{slug}.php
3. page-{id}.php
4. page.php
5. singular.php
6. index.php
分类页
1. category-{slug}.php
2. category-{id}.php
3. category.php
4. archive.php
5. index.php
标签文章列表页
1. tag-{slug}.php
2. tag-{id}.php
3. tag.php
4. archive.php
5. index.php
自定义文章分类列表页
1. taxonomy-{taxonomy}-{term}.php
2. taxonomy-{taxonomy}.php
3. taxonomy.php
4. archive.php
5. index.php
自定义文章类型列表页
archive-{post_type}.php
archive.php
index.php
作者文章列表页
1. author-{nicename}.php
2. author-{id}.php
3. author.php
4. archive.php
5. index.php
按日期归档文章列表页
1. date.php
2. archive.php
3. index.php
搜索结果页
1. search.php
2. index.php
404 页
1. 404.php
2. index.php
综上所述,一个最简单的 WordPress 主题,只需要一个 index.php 即可。
比较完善的一个 WordPress 主题,则需要 index.php、single.php、page.php、category.php、tag.php、author.php、date.php、search.php、404.php等页面。