본문으로 건너뛰기

패턴

패턴은 파일 기반 템플릿으로, 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을 통한 명시적 동기화 동기화 불필요
템플릿 잠금 예 아니요
사용 사례 사전 정의된 페이지 콘텐츠 재사용 가능한 블록 템플릿