5 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 3-4 years
  • United States
solotechno says
I’m using Option Tree to create color themes for my WordPress theme. I’m using a select type for the options. So for example the options are Default, Pink, Avocado. So if I understand the limited documentation my array would be this:
  • index 0 = Default
  • index 1 = Pink
  • index 2 = Avocado
In my functions.php file I am trying to do this:
function sltn_theme_color_option() {
    if ( function_exists( 'get_option_tree' ) ) {
    $color = get_option_tree( 'color_theme_option', '', false, true, -1 );
        if ( $color[2] ) {
            echo wp_enqueue_style( 'avocado', get_bloginfo( 'stylesheet_directory' ) . '/styles/avocado.css', false, '', 'all' );
        } elseif ( $color[1] ) {
            echo    wp_enqueue_style( 'pink', get_bloginfo( 'stylesheet_directory' ) . '/styles/pink.css', false, '', 'all' );
        } else {
            return; //Just show the default style which is style.css
        }
    }
}
add_action( 'wp_print_styles', 'sltn_theme_color_option' );

This doesn’t work, it just returns and shows the default style. I discovered that if I set any index to [0] then that style will show. I’m trying to show the style that the user picks in the select drop down. Can someone point out what it is I’m doing wrong?

Thanks, -Michael

3256 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Exclusive Author
  • Interviewed on the Envato Notes blog
  • Beta Tester
  • Author had a File in an Envato Bundle
  • Author had a Free File of the Month
+4 more
ParkerAndKent says

Hi Michael,

without having ever tried OptionTree, I guess you simply need tocheck which index of the list has been selected, so you should do the checks like this:

if ( (int)$color == 2 )

This because I don’t think that the $color option is valorized with an array, but simply with the selected index of the list.

Cheers,

Parker

5 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 3-4 years
  • United States
solotechno says

Parker,

No, unfortunately that didn’t work. Now it will only show the Pink theme (index 1) regardless of which color I select in the drop down.

-Michael

3256 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Exclusive Author
  • Interviewed on the Envato Notes blog
  • Beta Tester
  • Author had a File in an Envato Bundle
  • Author had a Free File of the Month
+4 more
ParkerAndKent says

Hi,

ok, no problem.

Let’s debug :)

After this line:

$color = get_option_tree( 'color_theme_option', '', false, true, -1 );

add this and tell me what it prints on the screen (better you look at the source HTML to see the result in a readable way):

print_r($color);

Is always a good thing to echo/print the variables we check, just to be sure to know what they really deliver :)

Parker

1141 posts
  • Bought between 100 and 499 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • Sold between 10 000 and 50 000 dollars
KarmaThemes says

Hey Michael,

that’s how I do it: http://pastie.org/2887353
All the best,
Mel for KarmaThemes

332 posts
  • Exclusive Author
  • Sold between 5 000 and 10 000 dollars
  • Has been a member for 4-5 years
  • Europe
  • Envato Studio (Microlancer) Beta Tester
  • Bought between 1 and 9 items
  • Referred between 1 and 9 users
dekciw says
KarmaThemes said
Hey Michael,

that’s how I do it: http://pastie.org/2887353
All the best,
Mel for KarmaThemes

This won’t work. Until he sets $skinpath.

1141 posts
  • Bought between 100 and 499 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • Sold between 10 000 and 50 000 dollars
KarmaThemes says

Yeah obviously he needs to set that, but I think he understands that :)

814 posts
  • Author had a Free File of the Month
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 1 and 9 items
  • Referred between 1 and 9 users
  • Serbia
  • Has been a member for 5-6 years
rvision_ says
KarmaThemes said
Hey Michael,

that’s how I do it: http://pastie.org/2887353
All the best,
Mel for KarmaThemes

This is Options framework if I am not mistaken. solotechno asked about OptionTree.

1141 posts
  • Bought between 100 and 499 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • Sold between 10 000 and 50 000 dollars
KarmaThemes says

Oh no – sorry!

5 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 3-4 years
  • United States
solotechno says

Hi Parker,

Sorry for the tardy reply, I’m in the states and I needed to catch a little sleep. When I print_r() I get:

Array ( [0] => Avocado ).

Hmm, this would confirm what I discovered earlier which is any of my array indices that are set to zero would display that color. Just to check I selected the color “Pink” from the drop down and did a print_r() again. Now Pink is at the zero index (Array ( [0] => Pink ).

This isn’t how an array is supposed to work is it? Apparently the Option Tree plugin sets the user’s selection to the zero index in the array?

More importantly, if that’s the case, how would I code for that situation? Maybe base the if statements on color?

Thanks for all the help so far,

-Michael

by
by
by
by
by
by