getolympus/olympus-dionysos-field-select

选择/多选字段,此组件是Olympus Dionysos字段的一部分。

v0.0.12 2023-12-17 22:37 UTC

This package is auto-updated.

Last update: 2024-09-18 21:26:48 UTC


README

Dionysos 选择字段

Olympus Component CodeFactor Grade Packagist Version MIT

此组件是用于WordPress的 Olympus Dionysos 字段 的一部分。
它使用默认的WordPress选择或多选字段。

composer require getolympus/olympus-dionysos-field-select

目录

字段初始化变量定义文本定义检索数据发布历史贡献

字段初始化

使用以下行在您的WordPress管理页面或自定义文章类型元字段中添加 选择字段

// Uniq choice version
return \GetOlympus\Dionysos\Field\Select::build('my_select_field_id', [
    'title'       => 'Select a Minion that you may know',
    'default'     => 'kevin',
    'description' => 'A very important question! Pay attention to it ;)',
    'multiple'    => false,
    'options'     => [
        'kevin' => 'Kevin',
        'mel'   => 'Mel',
        'dave'  => 'Dave',
        'bob'   => 'Bob',
    ],

    /**
     * Texts definition
     * @see the `Texts definition` section below
     */
    't_keyboard'   => 'Press the <kbd>CTRL</kbd> or <kbd>CMD</kbd> button to select more than one option.',
    't_no_options' => 'The field does no have any options.',
]);
// Multiple choice version
return \GetOlympus\Dionysos\Field\Select::build('my_multiselect_field_id', [
    'title'       => 'What are your preferred personas?',
    'default'     => ['minions', 'lapinscretins'],
    'description' => 'The White House needs your feedback asap!',
    'multiple'    => true,
    'options'     => [
        'minions'       => 'The Minions',
        'lapinscretins' => 'The Lapins Crétins',
        'marvel'        => 'All Marvel Superheroes',
        'franklin'      => 'Franklin (everything is possible)',
        'spongebob'     => 'Spongebob (nothing to say... Love it!)',
    ],

    /**
     * Texts definition
     * @see the `Texts definition` section below
     */
    't_keyboard'   => 'Press the <kbd>CTRL</kbd> or <kbd>CMD</kbd> button to select more than one option.',
    't_no_options' => 'The field does no have any options.',
]);

变量定义

变量定义取决于 多个

  • 设置为 false,将存储在数据库中的唯一字符串值
  • 设置为 true,将存储在数据库中的键值数组

在所有情况下

唯一选项

多个选项

文本定义

检索数据

使用简单的 get_option('my_select_field_id', '')get_option('my_multiselect_field_id', []) 从数据库检索您的值(参见 WordPress 参考

// Get select from Database
$select = get_option('my_select_field_id', '');

// Display value
echo '<h2><b>'.$select.'</b>, master of the ceremony</h2>';

// Get multiselect from Database
$multiselect = get_option('my_multiselect_field_id', []);

if (!empty($multiselect)) {
    echo '<p>And the nominees are:</p>';
    echo '<ul>';

    foreach ($multiselect as $value) {
        echo '<li>'.$value.'</li>'; // Will display key item options!
    }

    echo '</ul>';
}

发布历史

贡献

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

Achraf Chouk 用♥构建 ~ (c) 很长时间以来。