【问题标题】:Wordpress Theme Options field not retaining valueWordpress 主题选项字段不保留值
【发布时间】:2013-08-23 05:53:18
【问题描述】:

我确定是一个简单的问题,但我无法弄清楚。

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

?>

【问题讨论】:

  • 'sidebar2_on' => true,可以忽略。这是我不再需要的领域。

标签: php wordpress themes wordpress-theming


【解决方案1】:

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

Link to plugin

激活插件时包含文档。

【讨论】:

    猜你喜欢
    • 2012-08-13
    • 2014-08-02
    • 2012-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-09
    相关资源
    最近更新 更多