·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设开发 >> php网站开发 >> wordpress主题制作结构文件

wordpress主题制作结构文件

作者:佚名      php网站开发编辑:admin      更新时间:2022-07-23
WordPRess主题制作结构文件

下面是WordPress主题文件层次结构,它会告诉你:当WordPress显示特定的页面类型时,会使用哪个模板文件呢?只有了解了以下主题层次结构,你才能知道你的WordPress主题到底需要写哪些文件。

怎么看下面的文件层次结构?

以主页为例,下面有2个文件home.php和index.php,WordPress程序会从你的主题文件夹中依次查找这两个文件:

    1. 如果找到home.php,则使用home.php作为博客首页模板,即使你的主题文件夹中有index.php;
    2. 如果home.php未找到,则使用index.php作为首页模板;
    3. 如果home.php和index.php都找不到,你的主题将不会被WordPress识别,等于废物。
主页
    1. home.php
    2. index.php

文章页:

    1. single-{post_type}.php – 如果文章类型是videos(即视频),WordPress就会去查找single-videos.php(WordPress 3.0及以上版本支持)
    2. single.php
    3. index.php
页面
    1. 自定义模板 – 在WordPress后台创建页面的地方,右侧边栏可以选择页面的自定义模板
    2. page-{slug}.php – 如果页面的缩略名是news,WordPress将会查找 page-news.php(WordPress 2.9及以上版本支持)
    3. page-{id}.php – 如果页面ID是6,WordPress将会查找page-6.php
    4. page.php
    5. index.php
分类
    1. category-{slug}.php – 如果分类的缩略名为news,WordPress将会查找category-news.php(WordPress 2.9及以上版本支持)
    2. category-{id}.php -如果分类ID为6,WordPress将会查找category-6.php
    3. category.php
    4. archive.php
    5. index.php
标签
    1. tag-{slug}.php – 如果标签缩略名为sometag,WordPress将会查找tag-sometag.php
    2. tag-{id}.php – 如果标签ID为6,WordPress将会查找tag-6.php(WordPress 2.9及以上版本支持)
    3. tag.php
    4. archive.php
    5. index.php
作者
    1. author-{nicename}.php – 如果作者的昵称为rami,WordPress将会查找author-rami.php(WordPress 3.0及以上版本支持)
    2. author-{id}.php – 如果作者ID为6,WordPress将会查找author-6.php(WordPress 3.0及以上版本支持)
    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
附件页面
    1. MIME_type.php – 可以是任何MIME类型 (image.php, video.php, audio.php, application.php 或者其他).
    2. attachment.php
    3. single.php
    4. index.php

详细说明,请看WordPress官方文档:http://codex.wordpress.org/Template_Hierarchy