WordPress主题文件层次结构
以主页为例,下面有2个文件home.php和index.php,WordPress程序会从你的主题文件夹中依次查找这两个文件:
- 如果找到home.php,则使用home.php作为博客首页模板,即使你的主题文件夹中有index.php
- 如果home.php未找到,则使用index.php作为首页模板
- 如果home.php和index.php都找不到,你的主题将不会被WordPress识别
主页
- home.php
- index.php
文章页
- single-{post_type}.php – 如果文章类型是videos(即视频),WordPress就会去查找single-videos.php(WordPress 3.0及以上版本支持)
- single.php
- index.php
页面
- 自定义模板 – 在WordPress后台创建页面的地方,右侧边栏可以选择页面的自定义模板
- page-{slug}.php – 如果页面的缩略名是news,WordPress将会查找 page-news.php(WordPress 2.9及以上版本支持)
- page-{id}.php – 如果页面ID是6,WordPress将会查找page-6.php
- page.php
- index.php
分类
- category-{slug}.php – 如果分类的缩略名为news,WordPress将会查找category-news.php(WordPress 2.9及以上版本支持)
- category-{id}.php -如果分类ID为6,WordPress将会查找category-6.php
- category.php
- archive.php
- index.php
标签
- tag-{slug}.php – 如果标签缩略名为sometag,WordPress将会查找tag-sometag.php
- tag-{id}.php – 如果标签ID为6,WordPress将会查找tag-6.php(WordPress 2.9及以上版本支持)
- tag.php
- archive.php
- index.php
作者
- author-{nicename}.php – 如果作者的昵称为rami,WordPress将会查找author-rami.php(WordPress 3.0及以上版本支持)
- author-{id}.php – 如果作者ID为1,WordPress将会查找author-1.php(WordPress 3.0及以上版本支持)
- author.php
- archive.php
- index.php
日期页面
- date.php
- archive.php
- index.php
搜索结果
- search.php
- index.php
404 (未找到)页面
- 404.php
- index.php
附件页面
- MIME_type.php – 可以是任何MIME类型 (image.php, video.php, audio.php, application.php 或者其他)
- attachment.php
- single.php
- index.php
本文采用「CC BY-SA 4.0 CN」协议转载自互联网、仅供学习交流,内容版权归原作者所有,如涉作品、版权和其他问题请留言处理。