getolympus/olympus-dionysos-field-radio

单选框/复选框字段,该组件是Olympus Dionysos字段的一部分。

安装: 195

依赖: 2

建议者: 0

安全: 0

星星: 0

关注者: 2

分支: 0

开放问题: 0

语言:Less

类型:olympus-field

v0.0.18 2020-04-20 23:19 UTC

README

Dionysos单选框字段

Olympus Component CodeFactor Grade Packagist Version MIT

该组件是用于WordPressOlympus Dionysos字段的一部分。

composer require getolympus/olympus-dionysos-field-radio

目录

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

字段初始化

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

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

    /**
     * Texts definition
     * @see the `Texts definition` section below
     */
    't_no_options' => 'The field does no have any options.',
]);

变量定义

显示取决于mode

  • 设置为default(或inline),标签选项将显示在同一行上,作为inline-block显示
  • 设置为block,标签选项将每行显示一个,作为block显示
  • 设置为image,标签选项将显示为default模式,带有图像和叠加文本标签
  • 设置为image-block,标签选项将显示为block模式,带有图像和叠加文本标签
  • 设置为group,标签选项将显示为简单但高效的选项组

文本定义

检索数据

使用简单的get_option('my_radio_field_id', '')从数据库检索您的值(请参阅WordPress参考

// Get radio from Database
$radio = get_option('my_radio_field_id', '');

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

图像模式

要显示图像而不是简单的标签,请将mode设置为image,并按照以下方式构建字段选项

$options = [
    'key-name' => [
        'label' => 'Label item',
        'image' => 'https://label-image-url',
    ],
];

以下是一个完整的示例

return \GetOlympus\Dionysos\Field\Radio::build('my_radio_field_id', [
    'title'       => 'Select a Minion that you may know',
    'default'     => 'dave',
    'description' => 'A very important question! Pay attention to it ;)',
    'mode'        => 'image',
    'options'     => [
        'kevin' => [
            'label' => 'Kevin',
            'image' => 'https://vignette.wikia.nocookie.net/despicableme/images/1/1d/Kevin_minions.png/revision/latest/scale-to-width-down/350?cb=20170703052012',
        ],
        'mel'   => [
            'label' => 'Mel',
            'image' => 'https://vignette.wikia.nocookie.net/despicableme/images/2/2e/Mel_Minion_01.png/revision/latest/scale-to-width-down/350?cb=20160717135212',
        ],
        'dave'  => [
            'label' => 'Dave',
            'image' => 'https://vignette.wikia.nocookie.net/despicableme/images/7/71/Daveholdingcupcake.png/revision/latest/scale-to-width-down/350?cb=20130717145735',
        ],
        'bob'   => [
            'label' => 'Bob',
            'image' => 'https://vignette.wikia.nocookie.net/despicableme/images/c/ca/Bob-from-the-minions-movie.jpg/revision/latest/scale-to-width-down/350?cb=20151224154354',
        ],
    ],

    /**
     * Texts definitions
     * @see the `Texts definitions` section below
     */
    't_no_options' => 'The field does no have any options.',
]);

发布历史

贡献

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

Achraf Chouk用♥构建 ~ (c) 很久以来。