getolympus/olympus-content-field

此包已弃用且不再维护。作者建议使用 getolympus/olympus-dionysos-field-content 包。

内容字段,此组件是Olympus Dionysos字段的一部分。

v0.0.12 2020-04-19 23:59 UTC

This package is auto-updated.

Last update: 2020-04-20 00:00:06 UTC


README

此组件是 WordPressOlympus Dionysos字段 的一部分。

composer require getolympus/olympus-dionysos-field-content

Olympus Component CodeFactor Grade Packagist Version MIT

field-content-64.png

字段初始化

使用以下行在您的 WordPress 管理页面或自定义文章类型的元字段中添加 content field
注意 $identifier(第一个 ::build() 参数)设置为 false,因为不存储任何值在数据库中。

return \GetOlympus\Dionysos\Field\Content::build(false, [
    'title'   => 'The Dark Knight',
    'content' => '',
    'debug'   => false,
    'file'    => 'im_the_batman.php',
    'vars'    => [
        'question' => 'Who\'s the Batman?',
        'answers'  => [
            'the-joker'    => 'The Joker',
            'harley-quinn' => 'Harley Quinn',
            'bruce-wayne'  => 'Bruce Wayne, don\'t tell anybody!',
            'gotham-city'  => 'Gotham City',
        ],
    ],
]);

变量定义

变量 类型 未设置时的默认值 接受的值
title 字符串 '文件内容' empty
content 字符串 empty empty
debug 布尔型 empty empty
file 字符串 false truefalse
vars 数组 empty empty

说明

  • content 设置为显示HTML标签。如果文件不存在,可以将其用作后备
  • debug 设置为 true 以启用调试模式,以防文件包含失败
  • file 设置为定义要包含为 include_once PHP函数的PHP文件路径

变量使用

在包含的文件(本例中的 im_the_batman.php),您可以使用 $v 变量作为数组

// Display question
echo '<h2>'.stripslashes($v['question']).'</h2>';
echo '<ul>';

// Display answers choices with radio button
foreach ($v['answers'] as $k => $answer) {
    echo '<li class="'.$k.' is-the-batman">'.stripslashes($answer).'</li>';
}

echo '</ul>';

内容显示优先级

组件将按优先级显示

  1. 包含的 file 路径
  2. content 中的所有内容

注意:不要忘记将 debug 设置为 true 以在 file 不存在或不可读的情况下显示错误。

发布历史

0.0.12

  • 删除无用描述

0.0.11

  • 新Olympus组件兼容性
  • 更改存储库以成为Dionysos字段的一部分

0.0.10

  • 修复:在twig文件上显示内容原始显示

贡献

  1. 分支它 (https://github.com/GetOlympus/olympus-dionysos-field-content/fork)
  2. 创建您的功能分支 (git checkout -b feature/fooBar)
  3. 提交您的更改 (git commit -am 'Add some fooBar')
  4. 将分支推送到远程 (git push origin feature/fooBar)
  5. 创建一个新的拉取请求

Achraf Chouk 建造,自很久以前以来。