gamajo/theme-toolkit

构建基于配置的WordPress主题的组件。

0.6.0 2017-07-31 09:17 UTC

This package is auto-updated.

Last update: 2024-09-07 21:38:27 UTC


README

构建基于配置的WordPress主题的组件。

在构建主题时,将特定实现的配置与可重用逻辑分开不是很好吗?这就是使用配置编写可重用代码系列文章的出发点,也是此包实现的功能。

它使用BrightNucleus\Config包来管理配置对象,而本包中的类则消费它们,以提供以下简单方式:

  • 注册和预加载Google字体。
  • 添加和删除图片大小。
  • 取消设置(继承)页面模板。
  • 添加主题支持。
  • 注册和注销小工具区域(侧边栏)。
  • 注册和注销小工具。
  • 管理脚本和样式依赖。

安装

需要PHP 7.1。

在终端中,导航到包含您的主题的目录,然后

composer require gamajo/theme-toolkit

然后您可以按需自动加载(PSR-4)或引入文件。

使用方法

请参阅example-config.php。这通常位于您的主题中,位于config/defaults.php

然后,您的主题将包含一个函数,位于functions.php中,用于拉取此配置并加载单个组件,这些组件被称为砖块

// functions.php

namespace Gamajo\ExampleTheme;

use BrightNucleus\Config\ConfigFactory;
use Gamajo\ThemeToolkit\Dependencies;
use Gamajo\ThemeToolkit\GoogleFonts;
use Gamajo\ThemeToolkit\ImageSizes;
use Gamajo\ThemeToolkit\Templates;
use Gamajo\ThemeToolkit\ThemeSupport;
use Gamajo\ThemeToolkit\Widgets;
use Gamajo\ThemeToolkit\WidgetAreas;
use Gamajo\ThemeToolkit\ThemeToolkit;

defined( 'ABSPATH' ) || exit;

if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
	require __DIR__ . '/vendor/autoload.php';
}


add_action( 'after_setup_theme', __NAMESPACE__ . '\setup' );
/**
 * Theme setup.
 *
 * Compose the theme toolkit bricks.
 */
function setup() {
	$config_file = __DIR__ . '/config/defaults.php';
	$config = ConfigFactory::createSubConfig( $config_file, 'Gamajo\ExampleTheme' );

	// These bricks are run in admin and front-end.
	$bricks = [
		Dependencies::class,
		ImageSizes::class,
		Templates::class,
		ThemeSupport::class,
		Widgets::class,
		WidgetAreas::class,
	];

	// Apply logic in bricks, with configuration defined in config/defaults.php.
	ThemeToolkit::applyBricks($config, ...$bricks);


	if ( ! is_admin() ) {
		// Only front-end bricks.
		$bricks = [
			GoogleFonts::class,
		];

		ThemeToolkit::applyBricks($config, ...$bricks);

	}
}

'Gamajo\ExampleTheme'字符串与配置文件底部return中的两个键匹配。在配置和函数中将此更改为您公司的名称和主题名称。

您不必使用此包中的所有砖块;选择所需。

您可以将自己的砖块添加到您的主题中(在您的src/或类似目录中),然后在上述函数中使用它们。

对于Genesis框架用户,请参阅Genesis Theme Toolkit,它具有注册布局、面包屑参数等额外砖块。

变更日志

请参阅CHANGELOG.md

致谢

Gary Jones构建
版权所有 2017 Gamajo