cuberis/wp-componify

组件,我们的灵活内容系统。

0.1.0 2019-03-18 19:33 UTC

This package is not auto-updated.

Last update: 2024-09-29 05:48:35 UTC


README

Latest Version on Packagist

组件,我们的灵活内容系统。

安装

composer require cuberis/wp-componify.

设置与示例

  1. /templates/components/ 中设置新的模板部分以匹配 ACF 灵活内容布局的缩写名。
  2. 在您的页面模板中实例化新的 Componify 类。
  3. 放松身心,享受吧!
<?php while (have_posts()) : the_post(); ?>
  <article>
    <header>
      <h1 class="entry-title"><?php the_title(); ?></h1>
    </header>
    <div class="entry-content">
      <?php
        $components = new Componify();
        $components->render();
      ?>
    </div>
  </article>
<?php endwhile; ?>

参数

  • prefix(默认:null)- 获取带有前缀的组件字段集合。

过滤器

cuberis_set_component_html_attributes

/**
 * Example for modifying component wrapper attributes.
 *
 * @param array $attrs
 * @param string $slug
 * @return $attrs
 */
function cuberis_filter_component_html_attributes($attrs, $slug) {
  // Add a class modifier to just the text component.
  if ($slug === 'text') {
    $attrs['class'] .= ' component--example-modifier';
  }

  // Add a new attribute to all components.
  $attrs['data-id'] = uniqid();

  return $attrs;
}
add_filter('cuberis_set_component_html_attributes', 'cuberis_filter_component_html_attributes', 10, 2);