getolympus / olympus-dionysos-field-checkbox
复选框字段,该组件是Olympus Dionysos字段的一部分。
v0.0.1
2023-12-18 11:30 UTC
Requires (Dev)
- phpunit/phpunit: ~5.3
README
此组件是WordPress的Olympus Dionysos字段的一部分。
composer require getolympus/olympus-dionysos-field-checkbox
字段初始化
使用以下代码行在您的WordPress管理页面或自定义文章类型元字段中添加复选框字段
return \GetOlympus\Dionysos\Field\Checkbox::build('my_checkbox_field_id', [ 'title' => 'What are your preferred personas?', 'default' => ['minions', 'lapinscretins'], 'description' => 'The White House needs your feedback asap!', 'mode' => 'default', '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_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_checkbox_field_id', [])
从数据库中检索您的值(见WordPress参考)
// Get checkbox from Database $checkbox = get_option('my_checkbox_field_id', []); if (!empty($checkbox)) { echo '<p>And the nominees are:</p>'; echo '<ul>'; foreach ($checkbox as $value) { echo '<li>'.$value.'</li>'; // Will display key item options! } echo '</ul>'; }
图像模式
要显示图像而不是简单的标签,将mode
设置为image
,并按照以下方式构建字段的选项
$options = [ 'key-name' => [ 'label' => 'Label item', 'image' => 'https://label-image-url', ], ];
下面是一个完整的示例
return \GetOlympus\Dionysos\Field\Checkbox::build('my_checkbox_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.', ]);
发布历史
0.0.1
- 初始提交
贡献
- 分支它(https://github.com/GetOlympus/olympus-dionysos-field-checkbox/fork)
- 创建您的功能分支(
git checkout -b feature/fooBar
) - 提交您的更改(
git commit -am 'Add some fooBar'
) - 推送到分支(
git push origin feature/fooBar
) - 创建一个新的拉取请求
由Achraf Chouk用♥构建 ~ (c) 很久以来。