gutenbergdocs/docs/reference-guides/theme-json-reference/theme-json-v1.md
2025-10-22 01:40:18 +08:00

135 lines
4.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Theme.json 版本1参考文档
> 本文档是 `theme.json` **版本1** 的技术规范。该版本适用于 WordPress 5.8 及以上版本。
<div class="callout callout-alert">
Theme.json 版本2 已随 WordPress 5.9 发布。WordPress 将继续支持 theme.json 版本1但新功能将仅添加到[新版本文档](/docs/reference-guides/theme-json-reference/theme-json-living.md)中。
当您准备升级时,请参阅 [theme.json 迁移指南](/docs/reference-guides/theme-json-reference/theme-json-migrations.md#migrating-from-v1-to-v2)了解更新至最新版本的详细信息。
</div>
本参考指南列出了 `theme.json` 架构中定义的设置项和样式属性。关于如何在主题中使用 `theme.json` 文件的示例与指导,请参阅 [theme.json 使用指南](/docs/how-to-guides/themes/global-settings-and-styles.md)。
## JSON 架构
版本1的最终架构文件位于`https://schemas.wp.org/wp/5.8/theme.json`
各 WordPress 版本对应的 Theme.json 架构文件路径为:`https://schemas.wp.org/wp/{{version}}/theme.json`。例如 WordPress 5.8 的架构文件地址为:`https://schemas.wp.org/wp/5.8/theme.json`。
关于如何在编辑器中运用 JSON 架构,请参阅[使用 theme.json 进行开发](/docs/how-to-guides/themes/global-settings-and-styles.md#developing-with-themejson)。
## 设置项
### 边框
与边框相关的设置。
| 属性 | 类型 | 默认值 | 参数 |
| ------------- | ------- | ------- | ---- |
| customRadius | boolean | false | |
---
### 颜色
与颜色相关的设置。
| 属性 | 类型 | 默认值 | 参数 |
| ---------------- | ------- | ------- | -------------------- |
| custom | boolean | true | |
| customDuotone | boolean | true | |
| customGradient | boolean | true | |
| duotone | array | | colors, name, slug |
| gradients | array | | gradient, name, slug |
| link | boolean | false | |
| palette | array | | color, name, slug |
---
### 布局
与布局相关的设置。
| 属性 | 类型 | 默认值 | 参数 |
| ------------ | ------ | ------ | ---- |
| contentSize | string | | |
| wideSize | string | | |
---
### 间距
与间距相关的设置。
| 属性 | 类型 | 默认值 | 参数 |
| --------------- | ------- | ------------------ | ---- |
| customMargin | boolean | false | |
| customPadding | boolean | false | |
| units | array | px,em,rem,vh,vw,% | |
---
### 排版
与排版相关的设置。
| 属性 | 类型 | 默认值 | 参数 |
| ------------------ | ------- | ------- | --------------- |
| customFontSize | boolean | true | |
| customLineHeight | boolean | false | |
| dropCap | boolean | true | |
| fontSizes | array | | name, size, slug |
---
### 自定义
生成格式为 `--wp--custom--{键名}--{嵌套键名}: {值};` 的自定义 CSS 属性。`驼峰式命名`的键名将转换为`短横线命名法`以遵循 CSS 属性命名规范。不同层级的键名通过 `--` 分隔,因此键名中不应包含 `--`
---
## 样式
### 边框
边框样式。
| 属性 | 类型 | 参数 |
| ------ | ------ | ---- |
| radius | string | |
---
### 颜色
颜色样式。
| 属性 | 类型 | 参数 |
| ----------- | ------ | ---- |
| background | string | |
| gradient | string | |
| text | string | |
---
### 间距
间距样式。
| 属性 | 类型 | 参数 |
| ------- | ------ | ----------------------- |
| margin | object | bottom, left, right, top |
| padding | object | bottom, left, right, top |
---
### 排版
排版样式。
| 属性 | 类型 | 参数 |
| ------------ | ------ | ---- |
| fontSize | string | |
| lineHeight | string | |