Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

Danny Outlaw
677 PointsWhy isn't this working and is there a better way?
Im using a options panel in my Wordpress theme to output some CSS.
The option control is a on/off switch. I assume that means on = 0 and off = 1
That could be wrong as well.
Here is what I have in my php/css file
#logo img{
<?php if($center-logo == 0): ?>
margin:auto;
<?php else: ?>
margin:none;
}
<?php endif ?>
// For reference, the code below is what is in the options panel
array(
'id' => 'center-logo',
'type' => 'switch',
'title' => __('Center Logo', 'redux-framework-demo'),
'subtitle' => __('Look, it\'s on!', 'redux-framework-demo'),
'default' => true,
),

Danny Outlaw
677 PointsWhen set to 1 no CSS is applied. When set to 0 the margin:auto is applied no matter if the switch is on or off.

Marcus Parsons
15,719 PointsAh okay, thanks for that. Good luck, Danny!
5 Answers

mikes02
Courses Plus Student 16,968 PointsHave you tried:
#logo img {
<?php if($center-logo): ?>
margin:auto;
<?php else: ?>
margin:none;
<?php endif ?>
}

Danny Outlaw
677 PointsThat didnt seem to work either. :(

mikes02
Courses Plus Student 16,968 PointsDid some research on their documentation, have you tried:
#logo img {
<?php if($center-logo == TRUE): ?>
margin:auto;
<?php else: ?>
margin:none;
<?php endif ?>
}

Danny Outlaw
677 PointsYeah. I have tried that. The only way I get any kind of movement from the logo is if I use the number 0.
Otherwise nothing happens at all.

Danny Outlaw
677 PointsIt seems like maybe there is a problem with the ELSE statement? If I use the code you gave me and put in FLASE then the logo becomes centered.

mikes02
Courses Plus Student 16,968 PointsI would assume 1 would mean On and 0 would mean off, have you tried using 1 instead of 0?

mikes02
Courses Plus Student 16,968 Points#logo img {
<?php if($center-logo == 1): ?>
margin:auto;
<?php else: ?>
margin:none;
<?php endif ?>
}
If you have the center logo switch on, it seems that would equal 1, therefore margin: auto would be applied, else margin: none.

Danny Outlaw
677 PointsThats what I thought too.
But when I turn the switch off, the logo is still centered.

mikes02
Courses Plus Student 16,968 PointsHave you tried echoing out the value of that variable? From their documentation:
global $redux_demo;
echo 'Switch value: ' . $redux_demo['opt-switch'];
So you would use
global $redux_demo;
echo 'Switch value: ' . $redux_demo['center-logo'];
The only thing that may be different is the $redux_demo global. According to their documentation:
"Be sure to change $redux_demo to the value you specified in your opt_name argument."

Danny Outlaw
677 PointsYeah, I don't really see why I would need to do that. Doesnt make sense.

mikes02
Courses Plus Student 16,968 PointsTo see what the value is so you can ensure your if/else is looking for the appropriate value to compare.

Danny Outlaw
677 PointsStill struggling with this. Any help would be greatly appreciated.

mikes02
Courses Plus Student 16,968 PointsDid you try what I suggested above? Echoing out the variable to determine its value?
Marcus Parsons
15,719 PointsMarcus Parsons
15,719 PointsGenerally, binary selectors use 0 for false and 1 for true, so I would assume that 1 would be on and 0 would be off. Have you played around with these?