getolympus / olympus-dionysos-field-radio
Radio / Checkbox field, this component is a part of the Olympus Dionysos fields.
Installs: 204
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Language:Less
Type:olympus-field
Requires (Dev)
- phpunit/phpunit: ~5.3
README
Dionysos Radio Field
This component is a part of the Olympus Dionysos fields for WordPress.
composer require getolympus/olympus-dionysos-field-radio
Table of contents
Field initialization • Variables definition • Texts definition • Retrive data • Release history • Contributing
Field initialization
Use the following lines to add a radio field
in your WordPress admin pages or custom post type meta fields:
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.', ]);
Variables definition
The display depends on the mode
value:
- set to
default
(orinline
), labels options will be displayed on the same line, as aninline-block
display - set to
block
, labels options will be displayed each per line, as ablock
display - set to
image
, labels options will be displayed asdefault
mode, with images and overlay text label - set to
image-block
, labels options will be displayed asblock
mode, with images and overlay text label - set to
group
, labels options will be displayed as a simple but efficient group of choices
Texts definition
Retrive data
Retrieve your value from Database with a simple get_option('my_radio_field_id', '')
(see WordPress reference):
// Get radio from Database $radio = get_option('my_radio_field_id', ''); // Display value echo '<h2><b>'.$radio.'</b>, master of the ceremony</h2>';
Image mode
To display images instead of simple labels, set the mode
to image
and build the field's options as follow:
$options = [ 'key-name' => [ 'label' => 'Label item', 'image' => 'https://label-image-url', ], ];
Below, a full example:
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.', ]);
Release History
Contributing
- Fork it (https://github.com/GetOlympus/olympus-dionysos-field-radio/fork)
- Create your feature branch (
git checkout -b feature/fooBar
) - Commit your changes (
git commit -am 'Add some fooBar'
) - Push to the branch (
git push origin feature/fooBar
) - Create a new Pull Request
Built with ♥ by Achraf Chouk ~ (c) since a long time.