Tell me more ×
WordPress Answers 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

1 Answer

'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

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.