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 am currently using Options Framework Theme for making WordPress options panel. I created a checkbox in admin panel by this code in options.php

$options[] = array(
'name' => __('Input Checkbox Name', 'options_framework_theme'),
'desc' => __('Check to display.'),
'id' => 'example_checkbox_2',
'std' => 'true',
'type' => 'checkbox');

I want to display different content when the checkbox is checked or unchecked. So, I inserted this code in file template (footer.php)

<?php if ( of_get_option('example_checkbox2') != 'true') { ?>
        <p>checked</p>
    <?php } else { ?>
        <p>unchecked</p>
<?php } ?>

My problem is:

When I checked or uncheck the checkbox, "checked" is displayed in my footer.

Could anybody help how to retrieve and display content from checkbox correctly?

Any respond are highly appreciated.

Thank you.

share|improve this question
add comment

2 Answers

'true' should be '1':

$options[] = array(
    'name' => __('Input Checkbox Name', 'options_framework_theme'),
    'desc' => __('Check to display.'),
    'id' => 'example_checkbox_2',
    'std' => '1',
    'type' => 'checkbox'
);

and:

<?php if ( 1 == of_get_option('example_checkbox2') ) { ?>
        <p>checked</p>
    <?php } else { ?>
        <p>unchecked</p>
<?php } ?>
share|improve this answer
    
Thank you for your respond. It works very well. I made a miss-type before. I should type of_get_option('example_checkbox_2') instead of of_get_option('example_checkbox2') –  Kharis Blank Jul 28 '12 at 13:09
add comment

You almost got it, except use it like this on your template.

<?php if ( of_get_option('display_second_section_category') == '1' ) { ?>

share|improve this answer
1  
Please add an explanation to your answer: why could that solve the problem? –  toscho Mar 7 at 8:04
add comment

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.