getolympus / olympus-select-field
此软件包已被废弃且不再维护。作者建议使用 getolympus/olympus-dionysos-field-select 软件包。
选择/多选字段,该组件是Olympus Dionysos字段的一部分。
v0.0.12
2023-12-17 22:37 UTC
Requires (Dev)
- phpunit/phpunit: ~5.3
README
狄俄尼索斯选择字段
该组件是针对 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.', ]);
变量定义
变量定义取决于 multiple
值
- 设置为
false
,数据库中存储一个唯一的字符串值 - 设置为
true
,数据库中存储键值数组
在所有情况下
变量 | 类型 | 未设置时的默认值 | 接受的值 |
---|---|---|---|
title |
字符串 | '单选按钮' |
空字符串 |
description |
字符串 | 空字符串 | 空字符串 |
options |
数组 | 空字符串 | 键/值选项数组 |
唯一选择
变量 | 类型 | 未设置时的默认值 | 接受的值 |
---|---|---|---|
default |
字符串 | 空字符串 | 选项键之一 |
multiple |
布尔值 | false |
无其他选项 |
多选
变量 | 类型 | 未设置时的默认值 | 接受的值 |
---|---|---|---|
default |
字符串 | 空数组 | 包含选项键的数组 |
multiple |
布尔值 | true |
无其他选项 |
文本定义
代码 | 默认值 | 定义 |
---|---|---|
t_keyboard |
按下 CTRL 或 CMD 按钮以选择多个 选项。 |
用作提示,帮助用户使用多选字段 |
t_no_options |
该字段没有任何选项。 | 在未设置任何选项的情况下用作错误 |
检索数据
使用简单的 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>'; }
发布历史
版本 | 注意 |
---|---|
0.0.12 | 更改主要CSS类 |
0.0.11 | 新Olympus组件兼容性 将仓库改为Dionysos字段的一部分 |
0.0.10 | 从composer中移除twig依赖 |
贡献
- 分叉它 (https://github.com/GetOlympus/olympus-dionysos-field-select/fork)
- 创建你的功能分支 (
git checkout -b feature/fooBar
) - 提交你的更改 (
git commit -am '添加一些fooBar'
) - 推送到分支 (
git push origin feature/fooBar
) - 创建一个新的Pull Request
由Achraf Chouk使用♥构建 (Achraf Chouk) ~ 从很久以前起版权(c)。