Wordpress主题选项字段未保留值


Wordpress Theme Options field not retaining value

我肯定有一个简单的问题,但我无法解决。

我正在为我的wordpress模板编写一个主题选项页面,我已经设法将其保存在保存值的地方,我可以在网站上使用它们,但每当我重新加载主题选项页面时,所有表单字段都是空白的,以前应用的设置都不见了。我的代码在下面。

<?php
    //Theme Options Functionality is Below
if (get_option('pardue_theme_options')){
        $theme_options = get_option('pardue_theme_options');
} else {
    add_option('pardue_theme_options', array(
            'sidebar2_on' => true,
            'footer_text' => 'Made by William'
        ));

}
?>


 <?php add_action('admin_menu', 'theme_page_add');
function theme_page_add() {
    add_submenu_page('themes.php', 'Pardue Theme Options', 'Theme Options', 'administrator',  'themeoptions', 'theme_page_options');
}
function theme_page_options() {
        global $theme_options;

        $new_values = array(
            'footer_text' => htmlentities($_POST['footer_text'], ENT_QUOTES),

            );
        update_option('pardue_theme_options', $new_values);
        $theme_options = get_option('pardue_theme_options');
    echo '<div class="wrap">';
    echo '<h2>Theme Options</h2>';
?>
<form action="themes.php?page=themeoptions" method="post">

<label for="footer_text">Footer Text: </label><input name="footer_text" id="footer_text" value="<?php echo $theme_options['footer_text']; ?>" /> <br /> <br /> 
<label for="sidebar_checkbox">Sidebar 2 on: </label> <input name="sidebar_checkbox" id="sidebar_checkbox" value="on" type="checkbox" /> <br /> <br />
<input type="submit" value="Update Options" name="submit" />
</form>
<?php
    echo '</div>';
}
?>

我找到了一个很好的主题选项编码解决方案。下面链接中的插件使编写主题选项变得非常容易。

链接到插件

激活插件时会包含文档。