5 posts
  • Has been part of the Envato Community for over 3 years
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Located in 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
  • Has referred 100+ members
  • Has sold $250,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+9 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
  • Has been part of the Envato Community for over 3 years
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Located in 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
  • Has referred 100+ members
  • Has sold $250,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+9 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
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 100+ items on Envato Market
+2 more
KarmaThemes says

Hey Michael,

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

332 posts
  • Has referred 1+ members
  • Has sold $5,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 1+ items on Envato Market
+3 more
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
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 100+ items on Envato Market
+2 more
KarmaThemes says

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

815 posts
  • Has referred 1+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Contributed a free file of the month
+3 more
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
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 100+ items on Envato Market
+2 more
KarmaThemes says

Oh no – sorry!

5 posts
  • Has been part of the Envato Community for over 3 years
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Located in 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