WordPRess主题制作结构文件
下面是WordPress主题文件层次结构,它会告诉你:当WordPress显示特定的页面类型时,会使用哪个模板文件呢?只有了解了以下主题层次结构,你才能知道你的WordPress主题到底需要写哪些文件。
怎么看下面的文件层次结构?以主页为例,下面有2个文件home.php和index.php,WordPress程序会从你的主题文件夹中依次查找这两个文件:
如果找到home.php,则使用home.php作为博客首页模板,即使你的主题文件夹中有index.php;如果home.php未找到,则使用index.php作为首页模板;如果home.php和index.php都找不到,你的主题将不会被WordPress识别,等于废物。主页home.phpindex.php文章页:
single-{post_type}.php – 如果文章类型是videos(即视频),WordPress就会去查找single-videos.php(WordPress 3.0及以上版本支持)single.phpindex.php页面自定义模板 – 在WordPress后台创建页面的地方,右侧边栏可以选择页面的自定义模板page-{slug}.php – 如果页面的缩略名是news,WordPress将会查找 page-news.php(WordPress 2.9及以上版本支持)page-{id}.php – 如果页面ID是6,WordPress将会查找page-6.phppage.phpindex.php分类category-{slug}.php – 如果分类的缩略名为news,WordPress将会查找category-news.php(WordPress 2.9及以上版本支持)category-{id}.php -如果分类ID为6,WordPress将会查找category-6.phpcategory.phparchive.phpindex.php标签tag-{slug}.php – 如果标签缩略名为sometag,WordPress将会查找tag-sometag.phptag-{id}.php – 如果标签ID为6,WordPress将会查找tag-6.php(WordPress 2.9及以上版本支持)tag.phparchive.phpindex.php作者author-{nicename}.php – 如果作者的昵称为rami,WordPress将会查找author-rami.php(WordPress 3.0及以上版本支持)author-{id}.php – 如果作者ID为6,WordPress将会查找author-6.php(WordPress 3.0及以上版本支持)author.phparchive.phpindex.php日期页面date.phparchive.phpindex.php搜索结果search.phpindex.php404 (未找到)页面404.phpindex.php附件页面MIME_type.php – 可以是任何MIME类型 (image.php, video.php, audio.php, application.php 或者其他).attachment.phpsingle.phpindex.php详细说明,请看WordPress官方文档:http://codex.wordpress.org/Template_Hierarchy