REST API 文档

💡 云策文档标注

概述

本文档介绍了 WordPress 主题的 Schema 定义,包括主题记录中的字段及其属性,并提供了检索主题的 API 端点说明。这些信息适用于开发者通过 REST API 处理主题数据。

关键要点

  • Schema 定义了主题记录的字段,如 stylesheet、template、author、is_block_theme 等,所有字段默认只读,除非使用 _filter 参数或特定上下文。
  • 字段包括 JSON 数据类型、只读状态和上下文信息,例如 stylesheet 用于唯一标识主题,template 在子主题中指向父主题。
  • 提供两个 API 端点:GET /wp/v2/themes 用于检索主题列表(可带 status 参数过滤),GET /wp/v2/themes/<stylesheet> 用于检索特定主题。

代码示例

$ curl https://example.com/wp-json/wp/v2/themes
$ curl https://example.com/wp-json/wp/v2/themes/<stylesheet>

📄 原文内容

Schema

The schema defines all the fields that exist within a theme record. Any response from these endpoints can be expected to contain the fields below unless the `_filter` query parameter is used or the schema field only appears in a specific context.

stylesheet The theme's stylesheet. This uniquely identifies the theme.

JSON data type: string

Read only

Context:

template The theme's template. If this is a child theme, this refers to the parent theme, otherwise this is the same as the theme's stylesheet.

JSON data type: string

Read only

Context:

author The theme author.

JSON data type: object

Read only

Context:

author_uri The website of the theme author.

JSON data type: object

Read only

Context:

description A description of the theme.

JSON data type: object

Read only

Context:

is_block_theme Whether the theme is a block-based theme.

JSON data type: boolean

Read only

Context:

name The name of the theme.

JSON data type: object

Read only

Context:

requires_php The minimum PHP version required for the theme to work.

JSON data type: string

Read only

Context:

requires_wp The minimum WordPress version required for the theme to work.

JSON data type: string

Read only

Context:

screenshot The theme's screenshot URL.

JSON data type: string,
Format: uri

Read only

Context:

tags Tags indicating styles and features of the theme.

JSON data type: object

Read only

Context:

textdomain The theme's text domain.

JSON data type: string

Read only

Context:

theme_supports Features supported by this theme.

JSON data type: object

Read only

Context:

theme_uri The URI of the theme's webpage.

JSON data type: object

Read only

Context:

version The theme's current version.

JSON data type: string

Read only

Context:

status A named status for the theme.

JSON data type: string

Context:

One of: inactive, active

Retrieve a Theme

Definition & Example Request

GET /wp/v2/themes

Query this endpoint to retrieve a specific theme record.

$ curl https://example.com/wp-json/wp/v2/themes

Arguments

status Limit result set to themes assigned one or more statuses.

Retrieve a Theme

Definition & Example Request

GET /wp/v2/themes/<stylesheet>?)

Query this endpoint to retrieve a specific theme record.

$ curl https://example.com/wp-json/wp/v2/themes/<stylesheet>?)

Arguments

stylesheet The theme's stylesheet. This uniquely identifies the theme.