コンテンツへスキップ

パターン

パターンは、WordPressブロックパターンとして登録されるファイルベースのテンプレートです。ブロックインサーターに表示され、ユーザーは好きな場所に配置できます。

ページとは異なり、パターンはメモリに登録され、データベースの項目は作成されません。

pattern.json

各パターンフォルダーには、設定ファイルが必要ですpattern.json。

JSON
{
  "name": "hero-section",
  "title": "Hero Section",
  "description": "A hero section with heading and CTA",
  "categories": ["featured", "header"],
  "keywords": ["hero", "banner", "cta"]
}

プロパティ

プロパティ 型 デフォルト 説明
name string 必須 一意の識別子(blockstudio/を接頭辞に使用)
title string 必須 ブロックインサーターに表示するタイトル
description string "" インサーターに表示する説明
categories string[] [] パターンカテゴリー(e.gなど、featured、header、footer)
keywords string[] [] インサーター用の検索キーワード
viewportWidth number – プレビューの幅(ピクセル)
blockTypes string[] [] 関連付けるブロックタイプ
postTypes string[] [] 特定の投稿タイプに限定するかどうか
inserter boolean true インサーターに表示するかどうか

例

pattern.json:

JSON
{
  "name": "hero-with-cta",
  "title": "Hero with CTA",
  "description": "A full-width hero section with heading and call-to-action buttons",
  "categories": ["featured", "header"],
  "keywords": ["hero", "banner", "cta", "landing"],
  "viewportWidth": 1200
}

index.php:

HTML
<block name="core/cover" url="https://example.com/hero-bg.jpg" dimRatio="60">
  <h1>Build Something Amazing</h1>
  <p>Create beautiful websites with the power of blocks.</p>
  <block name="core/buttons">
    <block name="core/button" url="/get-started">Get Started</block>
    <block name="core/button" url="/learn-more" className="is-style-outline">Learn More</block>
  </block>
</block>

カスタムパス

デフォルトでは、Blockstudioはget_template_directory() . '/patterns'を検索します。フィルターでパスを追加できます。

PHP
add_filter( 'blockstudio/patterns/paths', function( $paths ) {
    $paths[] = get_stylesheet_directory() . '/custom-patterns';
    $paths[] = MY_PLUGIN_PATH . '/patterns';
    return $paths;
} );

複数のルートからファイルを組み合わせるランタイム統合では、ファイルシステムのスキャンを論理ディスカバリーソースに置き換えられます。 パターンのマニフェストとソーステンプレートは、最終的に表示される論理インベントリから解決されます。

PHP API

PHP
// Get all registered patterns
$patterns = Blockstudio\Patterns::patterns();

// Get a specific pattern
$pattern = Blockstudio\Patterns::get_pattern('hero-section');

// Get registered paths
$paths = Blockstudio\Patterns::get_registered_paths();

ページとの比較

項目 ページ パターン
保存先 投稿としてデータベースに同期 メモリに登録
設定 page.json pattern.json
同期 wp bs pages syncを使った明示的な同期 同期不要
テンプレートロック あり なし
用途 定義済みのページコンテンツ 再利用可能なブロックテンプレート