Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to figure out how to get the results from a select box option and apply them to my theme. When I use a text input or color picker it works fine. But when I use a select box, nothing is changing. Here's the option:

$options['color_scheme'] = array(
        'name' => __('Color Scheme', 'text-domain'),
        'desc' => __('Select a color scheme.', 'text-domain'),
        'id' => 'color_scheme',
        'std' => 'blue',
        'type' => 'select',
        'class' => 'mini',
        'options' => array('blue', 'yellow'));

This code below is where I'm trying to output certain option based on the selection:

if ( of_get_option('color_scheme') == "blue") {
                $output .= "#header {background:#000066;}\n";
            }
    else if ( of_get_option('color_scheme') == "yellow") {
                $output .= "#header {background:#FFFF66;}\n";
            }

if ($output <> '') {
            $output = "<!-- Custom Styling -->\n<style type=\"text/css\">\n" . $output . "</style>\n";
            echo $output;
        }
share|improve this question
1  
Is that your full code? You are not printing your $output you are only storing it in a variable. If it is echo your result instead. Also, keep your else if together like elseif otherwise it can break if you ever use that syntax style without curly braces. –  userabuser Jan 23 '13 at 4:59
    
@userabuser No, that's not my full code. I've added the portion of the code where I print the output. Note that it works fine for input variables and color pickers. I'm just running into a problem with the select box. –  chowwy Jan 23 '13 at 5:22

1 Answer 1

up vote 2 down vote accepted

I use the same options framework plugin and this is how I specify a select menu using this framework;

$test_array = array(
    'one' => __('One', 'options_framework_theme'),
    'two' => __('Two', 'options_framework_theme'),
    'three' => __('Three', 'options_framework_theme'),
    'four' => __('Four', 'options_framework_theme'),
    'five' => __('Five', 'options_framework_theme')
);

$options[] = array(
    'name' => __('Select a Tag', 'options_check'),
    'desc' => __('Passed an array of tags with term_id and term_name', 'options_check'),
    'id' => 'example_select_tags',
    'type' => 'select',
    'options' => $test_array);

Note that the options parameter accepts;

'options' => array('value' => 'label')

Where as in your instance you have only specified the label using;

'options' => array('blue', 'yellow')

Which means blue has a value of 0 and yellow has a value of 1.

Therefore the following is incorrect,

if ( of_get_option('color_scheme') == "blue") 

As it should be,

if ( of_get_option('color_scheme') == 0) //0 for blue 1 for yellow

If you want to check by a value name of blue or yellow then your array should look like,

'options' => array(
    'blue' => 'Blue',
    'yellow' => 'Yellow'
 )
share|improve this answer
    
Thank you. Accepted and upvoted. I didn't realize the array needed to be a key/value pair. Works beautifully. –  chowwy Jan 23 '13 at 7:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.