0

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.

1

'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 } ?>
  • 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
0

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

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

  • 1
    Please add an explanation to your answer: why could that solve the problem? – fuxia Mar 7 '14 at 8:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.