REST API 文档

💡 云策文档标注

概述

本文档介绍了区块模式(Block Patterns)的架构定义和检索方法。区块模式记录包含多个字段,用于描述模式的基本信息和用途,开发者可以通过 REST API 端点获取特定模式记录。

关键要点

  • 区块模式架构定义了多个字段,如 name、title、content、description、viewport_width、inserter、categories、keywords、block_types、post_types、template_types 和 source,这些字段在响应中默认包含,除非使用 _filter 查询参数或字段仅出现在特定上下文中。
  • 所有字段均为只读,JSON 数据类型包括字符串、数字、布尔值和数组,上下文通常为 view、edit 和 embed。
  • source 字段表示模式来源,可选值包括 core、plugin、theme、pattern-directory/core、pattern-directory/theme 和 pattern-directory/featured。
  • 可以通过 GET /wp/v2/block-patterns/patterns 端点检索区块模式记录,该端点无需参数,使用 curl 命令示例进行请求。

代码示例

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

📄 原文内容

Schema

The schema defines all the fields that exist within a block pattern 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.

name The pattern name.

JSON data type: string

Read only

Context: view, edit, embed

title The pattern title, in human readable format.

JSON data type: string

Read only

Context: view, edit, embed

content The pattern content.

JSON data type: string

Read only

Context: view, edit, embed

description The pattern detailed description.

JSON data type: string

Read only

Context: view, edit, embed

viewport_width The pattern viewport width for inserter preview.

JSON data type: number

Read only

Context: view, edit, embed

inserter Determines whether the pattern is visible in inserter.

JSON data type: boolean

Read only

Context: view, edit, embed

categories The pattern category slugs.

JSON data type: array

Read only

Context: view, edit, embed

keywords The pattern keywords.

JSON data type: array

Read only

Context: view, edit, embed

block_types Block types that the pattern is intended to be used with.

JSON data type: array

Read only

Context: view, edit, embed

post_types An array of post types that the pattern is restricted to be used with.

JSON data type: array

Read only

Context: view, edit, embed

template_types An array of template types where the pattern fits.

JSON data type: array

Read only

Context: view, edit, embed

source Where the pattern comes from e.g. core

JSON data type: string

Read only

Context: view, edit, embed

One of: core, plugin, theme, pattern-directory/core, pattern-directory/theme, pattern-directory/featured

Retrieve a Block Pattern

Definition & Example Request

GET /wp/v2/block-patterns/patterns

Query this endpoint to retrieve a specific block pattern record.

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

There are no arguments for this endpoint.