虽然从技术上讲,WordPress主题仅需要两个文件(index.php和style.css),但它们通常由许多文件组成。这意味着它们会很快变得杂乱无章!
主题文件夹和文件结构
WP默认的自带主题是非常好的示例。例如,以下是 Twenty Seventeen 主题的文件结构:
assets (dir)
- css (dir)
- images (dir)
- js (dir)
inc (dir)
template-parts (dir)
- footer (dir)
- header (dir)
- navigation (dir)
- page (dir)
- post (dir)
404.php
archive.php
comments.php
footer.php
front-page.php
functions.php
header.php
index.php
page.php
README.txt
rtl.css
screenshot.png
search.php
searchform.php
sidebar.php
single.php
style.css
您可以看到主要主题模板文件位于根目录中,而JavaScript、CSS、图像位于 assets 目录中,模板部分位于 template-parts 的相应子目录下,并且与核心功能相关的功能集合被放在inc目录中。
目前,WordPress主题内没有必需的文件夹。但是,WordPress默认情况下会识别以下文件夹。
style.css应该位于主题的根目录中,而不是CSS目录中。
本文深入解析WordPress主题的文件结构,包括必要的index.php和style.css,以及常见子目录如assets、inc和template-parts的作用。了解如何组织主题文件可以提高开发效率。

被折叠的 条评论
为什么被折叠?



