wordpress主题复选框

时间:2012-01-08 10:45:14

标签: php checkbox

这是我必须在主题选项页面中显示复选框的代码:

$options[] = array( "name" => "Enable/Disable Slider",
            "desc" => "If you don´t want to see the slider on your homepage you can disable it here.",
            "id" => $shortname."_onoffslider",
            "std" => "",
            "type" => "checkbox",
            "class" => "");

现在复选框就在那里。此外,我还有一些代码可以在模板中回显值true或false。像这样:

        <p>
        <?php if( get_option('_onoffslider') != '') { ?>
        <?php echo get_option('_onoffslider'); ?>

        <?php } else { ?>

        It is ON!

        <?php } ?>
    </p>    

在模板页面中显示“It is ON!”无论打开还是关闭复选框,都会显示。我知道代码错了但我无法修复它。

有任何帮助吗?谢谢=)

1 个答案:

答案 0 :(得分:0)

应该是

 <p>
        <?php $shortname="whateveryouhadchosen"; ?>
        <?php if( get_option($shortname.'_onoffslider') != '') { ?>
        <?php echo get_option($shortname.'_onoffslider'); ?>

        <?php } else { ?>

        It is ON!

        <?php } ?>
    </p>