5 posts
  • 4 Years of Membership
  • Collector Level 2
  • Exclusive Author
  • 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
  • Affiliate Level 4
  • Author Level 9
  • Collector Level 2
  • Top Monthly Author
+11 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
  • 4 Years of Membership
  • Collector Level 2
  • Exclusive Author
  • 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
  • Affiliate Level 4
  • Author Level 9
  • Collector Level 2
  • Top Monthly Author
+11 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
  • 5 Years of Membership
  • Affiliate Level 1
  • Author Level 6
  • Collector Level 4
+3 more
KarmaThemes
says

Hey Michael,

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

332 posts
  • Affiliate Level 1
  • Author Level 4
  • Beta Tester
  • Collector Level 1
+2 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
  • 5 Years of Membership
  • Affiliate Level 1
  • Author Level 6
  • Collector Level 4
+3 more
KarmaThemes
says

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

815 posts
  • Affiliate Level 1
  • Author Level 5
  • Collector Level 1
  • Freebie
+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
  • 5 Years of Membership
  • Affiliate Level 1
  • Author Level 6
  • Collector Level 4
+3 more
KarmaThemes
says

Oh no – sorry!

5 posts
  • 4 Years of Membership
  • Collector Level 2
  • Exclusive Author
  • 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