PHP code example of getolympus / olympus-select-field
1. Go to this page and download the library: Download getolympus/olympus-select-field library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
getolympus / olympus-select-field example snippets
// 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.',
]);
// 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>';
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.