lachlanarthur/sage8-acf-wp-blocks

从 Sage 8 模板和 ACF 字段创建 Gutenberg 块。

安装次数: 7,400

依赖项: 0

建议者: 0

安全性: 0

星标: 1

关注者: 3

分支: 66

类型:wordpress-plugin

v1.0 2020-12-16 01:47 UTC

This package is auto-updated.

Last update: 2024-09-16 09:48:16 UTC


README

通过将模板添加到您的 Sage 8 主题中生成 ACF Gutenberg 块。此包是从 Sage 9 版本 forked,由 MWDelaney 开发,该版本主要基于 这篇文章,作者是 nicoprat

安装

在您的基于 Sage 8 的主题目录中运行以下命令

composer require "lachlanarthur/sage8-acf-wp-blocks"

要求

  • Wordpress 5+
  • Advanced Custom Fields 5.8+
  • 基于 Sage 8 的主题(见 原始版本 以了解 Sage 9)

创建块

将模板添加到 your-theme/wp-blocks,其中获取和使用 ACF 数据。每个模板都需要一个包含一些数据的元数据注释块

<?php
/**
 * Title: 
 * Description: 
 * Category: 
 * Icon: 
 * Keywords: 
 * Post Types: 
 * Default Mode: 
 * Default Alignment: 
 */

示例块模板

<?php
/**
 * Title: Testimonial
 * Description: Customer testimonial
 * Category: formatting
 * Icon: admin-comments
 * Keywords: testimonial quote
 * Post Types: post page
 * Default Mode: preview
 * Default Alignment: full
 */
?>

<blockquote data-<?= sanitize_html_class( $block['id'] ) ?> class="<?= esc_attr( $block['classes'] ) ?>">
  <p><?= get_field('testimonial') ?></p>
  <cite>
    <span><?= get_field('author') ?></span>
  </cite>
</blockquote>

<style type="text/css">
  [data-<?= sanitize_html_class( $block['id'] ) ?>] {
    background: <?= get_field('background_color') ?>;
    color: <?= get_field('text_color') ?>;
  }
</style>

块选项

创建 ACF 字段

一旦创建了块,您就可以使用 WordPress 中的标准自定义字段界面将 ACF 字段分配给它。我们建议使用 sage-advanced-custom-fields 将您的 ACF 字段与 Sage 一起进行版本控制。

更改块目录

可以使用过滤器 sage8-acf-wp-blocks-paths 来更改 wp-blocks 目录。

add_filter('sage8-acf-wp-blocks-paths', function ($paths) {
  return ['templates/blocks', 'another-path'];
}, 10, 1);