承接 lachlanarthur/sage8-acf-wp-blocks 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

lachlanarthur/sage8-acf-wp-blocks

最新稳定版本:v1.0

Composer 安装命令:

composer require lachlanarthur/sage8-acf-wp-blocks

包简介

Create Gutenberg blocks from Sage 8 templates and ACF fields.

README 文档

README

Generate ACF Gutenberg blocks just by adding templates to your Sage 8 theme. This package is forked from the Sage 9 version by MWDelaney which is based heavily on this article by nicoprat.

Installation

Run the following in your Sage 8-based theme directory:

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

Requirements

  • Wordpress 5+
  • Advanced Custom Fields 5.8+
  • Theme based on Sage 8 (See the original for Sage 9)

Creating blocks

Add templates to your-theme/wp-blocks which get and use ACF data. Each template requires a metadata comment block with some data in it:

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

Example block template

<?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>

Block options

Option Value
Category common
formatting
layout
widgets
embed
Create your own
Icon The name of a Dashicon
Post Types Space-delimited list of post types
Default Mode preview
edit
Default Alignment left
center
right
wide
full

Creating ACF fields

Once a block is created you'll be able to assign ACF fields to it using the standard Custom Fields interface in WordPress. We recommend using sage-advanced-custom-fields to keep your ACF fields in version control with Sage.

Changing the blocks directory

The wp-blocks directory can be changed with the filter sage8-acf-wp-blocks-paths:

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

统计信息

  • 总下载量: 7.97k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 67
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-03-18