主样式表 (style.css)

style.css 是每个 WordPress 主题所需的样式表 (CSS) 文件。它控制网站页面的呈现(视觉设计和布局)。

地点

为了让 WordPress 将主题模板文件集识别为有效主题,style.css 文件需要位于主题的根目录中,而不是子目录中。

有关如何在主题中包含 style.css 文件的更多详细说明,请参阅排队脚本和样式的“样式表”部分。

基本结构

WordPress 使用 style.css 的标题注释部分在外观 (Themes) 仪表板面板中显示有关主题的信息。

例子

这是 style.css 的标头部分的示例。

/*
Theme Name: Twenty Twenty
Theme URI: https://wordpress.org/themes/twentytwenty/
Author: the WordPress team
Author URI: https://wordpress.org/
Description: Our default theme for 2020 is designed to take full advantage of the flexibility of the block editor. Organizations and businesses have the ability to create dynamic landing pages with endless layouts using the group and column blocks. The centered content column and fine-tuned typography also makes it perfect for traditional blogs. Complete editor styles give you a good idea of what your content will look like, even before you publish. You can give your site a personal touch by changing the background colors and the accent color in the Customizer. The colors of all elements on your site are automatically calculated based on the colors you pick, ensuring a high, accessible color contrast for your visitors.
Tags: blog, one-column, custom-background, custom-colors, custom-logo, custom-menu, editor-style, featured-images, footer-widgets, full-width-template, rtl-language-support, sticky-post, theme-options, threaded-comments, translation-ready, block-styles, wide-blocks, accessibility-ready
Version: 1.3
Requires at least: 5.0
Tested up to: 5.4
Requires PHP: 7.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: twentytwenty
This theme, like WordPress, is licensed under the GPL.
Use it to make something cool, have fun, and share what you've learned with others.
*/

笔记:WordPress 主题存储库使用此文件中“版本”之后的数字来确定主题是否有可用的新版本。

说明

WordPress 主题存储库中的主题需要用( * )表示的项目。

  • 主题名称(*):主题的名称。
  • Theme URI:公共网页的 URL,用户可以在其中找到有关主题的更多信息。
  • 作者(*):开发主题的个人或组织的名称。建议使用主题作者的 wordpress.org 用户名。
  • 作者 URI:创作个人或组织的 URL。
  • 说明(*):主题的简短说明。
  • 版本(*):主题的版本,以XX或XXX格式书写。
  • 至少需要 (*):主题将使用的最旧的主要 WordPress 版本,以 XX 格式编写。主题只需要支持最后三个版本。
  • **测试到 (*):**主题测试到的最后一个主要 WordPress 版本,即 5.4。只写数字,格式为 XX。
  • Requires PHP (*) : 支持的最早的 PHP 版本,XX 格式,只有数字
  • 许可证(*):主题的许可证。
  • 许可证 URI (*):主题许可证的 URL。
  • 文本域(*):用于翻译的文本域的字符串。
  • 标签:允许用户使用标签过滤器查找主题的词或短语。完整的标签列表在Theme Review Handbook中。
  • 域路径:用于使 WordPress 知道在禁用主题时在哪里可以找到翻译。默认为/languages.

在所需的标题部分之后,style.css 可以包含常规 CSS 文件所具有的任何内容。

儿童主题的 Style.css

如果您的主题是子主题, 则 style.css 标头中需要模板行。

/*
Theme Name: My Child Theme
Template: twentytwenty
*/

有关创建子主题的更多信息,请访问子主题页面。