select(sample)

Display a single select drop down.

Option Details & Parameters

Type: select

Returns: string

Can be placed in: Admin Panels , Admin Tabs , Meta Boxes , Theme Customizer

Parameter Type Description Ver
name string The name of the option, for display purposes only.
id string A unique ID for this option. This ID will be used to get the value for this option.
desc string The description to display together with this option.
options array An associative array containing value – label pair options displayed in the select drop down. Use a two dimensional array if you want to display grouped options.
default string (Optional) The default value for this option.
multiple boolean (Optional) If true, multiple options can be selected by holding down the shift key. Defaults to false. 1.9
livepreview string (Optional) jQuery code that updates something in your site in the live preview. Only used when the option is placed in a theme customizer section. Refer to Livepreview for more information on this parameter.
css string (Optional) CSS rules to be used with this option. Only used when the option is placed in an admin page / panel or a theme customizer section. Refer to Generate CSS Automatically for your options for more information on this parameter.

Examples

Creating a select option:

$panel->createOption( array(
'name' => 'My Select Option',
'id' => 'my_select_option',
'type' => 'select',
'desc' => 'This is our option',
'options' => array(
'1' => 'Option one',
'2' => 'Option two',
'3' => 'Option three',
),
'default' => '2',
) );

Creating a select option with grouped options:

$panel->createOption( array(
'name' => 'My Select Option',
'id' => 'my_select_option',
'type' => 'select',
'desc' => 'This is our option',
'options' => array(
'Group 1' => array(
'1' => 'Option one',
'2' => 'Option two',
),
'Group 2' => array(
'3' => 'Option three',
),
),
'default' => '2',
) );

Getting the Results

Let’s say you have this option:

$panel->createOption( array(
'name' => 'Select a Color',
'id' => 'my_button_color',
'type' => 'select',
'desc' => 'Choose a color',
'options' => array(
'red' => 'Red',
'blue' => 'Blue',
'silver' => 'Silver',
),
'default' => 'blue',
) );

Using the select option value in your CSS:

add_action( 'wp_head', 'my_plugin_use_select_option' );
function my_plugin_use_select_option() {
$titan = TitanFramework::getInstance( 'my-theme' );
echo "<style>
.my_buttons {
background-color: <?php echo $titan->getOption( 'my_button_color' ) ?>;
}
</style>"; 
}