Wordpress主题选项字段不保留价值

时间:2013-08-21 01:44:07

标签: php wordpress themes wordpress-theming

我有一个简单的问题,但我无法弄明白。

我正在为我的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>';
}

?>

1 个答案:

答案 0 :(得分:0)

我找到了一个很好的解决方案来编码我的主题选项。下面链接中的插件可以很容易地编写主题选项。

Link to plugin

激活插件时会包含文档。