getolympus/olympus-select-field

此软件包已被废弃且不再维护。作者建议使用 getolympus/olympus-dionysos-field-select 软件包。

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

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

This package is auto-updated.

Last update: 2023-12-18 19:53:11 UTC


README

field-select.png

狄俄尼索斯选择字段

Olympus Component CodeFactor Grade Packagist Version MIT

该组件是针对 WordPressOlympus 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 按下 CTRLCMD
按钮以选择多个
选项。
用作提示,帮助用户使用多选字段
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依赖

贡献

  1. 分叉它 (https://github.com/GetOlympus/olympus-dionysos-field-select/fork)
  2. 创建你的功能分支 (git checkout -b feature/fooBar)
  3. 提交你的更改 (git commit -am '添加一些fooBar')
  4. 推送到分支 (git push origin feature/fooBar)
  5. 创建一个新的Pull Request

由Achraf Chouk使用♥构建 (Achraf Chouk) ~ 从很久以前起版权(c)。