主题开发文档

工具与资源

💡 云策文档标注

概述

本文档为 WordPress 开发者提供了构建主题时所需的工具和资源,涵盖块主题和经典主题的开发辅助工具、代码标准检查工具以及培训材料。

关键要点

  • 块主题资源:包括 Create Block Theme 插件和 Theme Generator 工具,用于创建和定制块主题,支持从空白或预定义模板开始。
  • 经典主题资源:推荐使用 _s (Underscores) 启动主题作为经典主题的基础框架。
  • 代码标准工具:提供 WordPress Coding Standards for PHP_CodeSniffer、WPThemeReview Standards for PHP_CodeSniffer 和 Theme Check Plugin,用于自动化代码分析和确保主题符合 WordPress 标准。
  • 培训材料:包含全站编辑、块主题解剖、落地页构建等主题开发教程,可在 learn.wordpress.org 上找到更多课程。

注意事项

  • 社区工具众多,本文档未涵盖所有可能对开发有帮助的工具,开发者可自行探索其他资源。
  • 使用 Create Block Theme 插件时,需确保已安装并激活最新版本的 Gutenberg 插件。
  • Theme Generator 提供不同级别的主题模板,开发者可根据需求选择,并可能需要移除示例内容。
  • Theme Check Plugin 可用于在提交主题到 WordPress.org 仓库前进行预测试,以解决潜在问题。

📄 原文内容

Whether you’re building your very first theme or your tenth, the following resources are meant to help ease the process. Keep in mind that there are various community tools not mentioned here as well but that still might aid in your efforts. 

Block themes

A block theme is a type of WordPress theme built using blocks. You can read more about these themes in the Block Theme section.

Create Block Theme plugin 

This plugin was created by various community members. This tool can create standalone block themes and child themes, depending on your needs. Here are the high-level steps: 

  1. Install and activate the Create Block Theme plugin. You will also need to be running the latest version of the Gutenberg plugin.
  2. Make changes to your site design using the Customizer and Site Editor.
  3. Edit your templates using the Site Editor. For some things, you might need to edit the template files again later.
  4. In the WordPress Admin Dashboard, under Appearance there will be a new page called “Create Block Theme”. You can add the details for the theme here. These details will be used in the style.css file. 
  5. Click the “Create Block Theme” button. From there, a zip file will be downloaded which will contain all the files for your theme.

Theme Generator

This tool was created by Carolina Nymark and it allows you to create three different types of themes to start from:

  • No Code: for non-developers who want to start from a blank theme and build directly in the Site Editor.
  • Empty: for developers to make their own with six templates and a theme.json with empty settings for you to complete.
  • Basic: for developers to explore with six templates, two template parts, three block patterns, and two custom block styles alongside some initial theme.json settings.
  • Advanced: for developers to explore with seven templates, five template parts, seven patterns, various block styles, and a more robust theme.json. It’s common to want to remove some of the examples.

Comparison Chart

Tool Child theme options? Template creation? Theme.json Controls Demo content
Create Block Theme plugin Yes Yes No No
Theme Generator No Yes Yes Yes

Classic themes

A classic theme is built with PHP templates, functions.php, and more. You can read more about these themes in the Classic Theme section.

The _s (Underscores) starter theme is a tool for initializing and creating a classic theme.

Tools

WordPress Coding Standards for PHP_CodeSniffer

This project is a collection of PHP_CodeSniffer rules (sniffs) that are used to validate code developed for WordPress, but can also be used when developing themes and plugins. They encompass coding style along with established best practices regarding interoperability, translatability, and security in the WordPress ecosystem, according to the official WordPress Coding Standards.

WordPress Coding Standards for PHP_CodeSniffer

The WPThemeReview Standards for PHP_CodeSniffer are a collection of sniffs that aim to automate the code analysis part of the Theme Review Process as much as possible using static code analysis.
The WPThemeReview Standards require the WordPress Coding Standards.

WPThemeReview Standards for PHP_CodeSniffer 

Theme Check Plugin

The theme check plugin is an easy way to test your theme and make sure it’s up to spec with the latest theme review standards. With it, you can run all the same automated testing tools on your theme that WordPress.org uses for theme submissions. This allows you to resolve any issues that might come up before trying to submit your theme to the theme repository. 

Training material

Site Design with Full Site Editing: Part 1, Part 2, Part 3

Anatomy of a Block Theme

Creating a landing page with a block theme

Building a home page with a block theme

Using Schema with WordPress theme.json

Create a Basic Child Theme for Block Themes

Find more theme lessons on learn.wordpress.org.