【问题标题】:Can't save theme options, following a tutorial from tutsplus无法保存主题选项,遵循 tutsplus 的教程
【发布时间】:2014-01-22 00:38:47
【问题描述】:

我知道之前有人问过这个问题,为什么我的代码没有保存,但是这个教程最近被一位用户推荐在这里,我一直在关注它从 tuts plus,(显然改变变量和选项以适应我的需要),但由于某种原因,会出现显示设置已保存的小栏,并且会出现保存按钮,表单本身,看起来一切正常,但是当我点击保存时,它从表单中消失了。请记住,我只尝试保存第一个选项的设置,即站点徽标 url。这是我的代码,它正确地包含在 functions.php 文件中。

PS:很抱歉,PHP 和 HTML 将它们放在一起,但这是在一篇文章中将它们放在一起的唯一方法,另外,我喜欢在完成后将它们放在单独的文件中。

<?php
 if (!current_user_can('manage_options')) {
    wp_die('You do not have permission to view this page, if you believe that this is a mistake, please contact your system administrator, or try closing the tab and come back.');
}


 add_action("admin_menu", "setup_where_now_admin_menus");

 function setup_where_now_admin_menus() {
    add_menu_page('Front Door Theme Options', 'Front Door Theme Options', 'manage_options', 'where_now_elements', 'where_now_options') ;
}
?>

<?php
function where_now_options() { ?>
<div class="wrap">
<h2>Front Door Web Design Custom Theme Options</h2>
<form method="post" action="">


<h4>Site Logo URL</h4>
<p>Remember, this is the image used in places like your header, or anywhere else you want your logo to appear, and if you are having trouble remembering how to use this feature, you can always upload your new logo to the media section in Wordpress, get the URL from the specific images page, and then paste it here!</p>     
<input type="text" name="site_logo" value="<?php echo $site_logo;?>" size="25">


    <h4>Analytics Tracking Code</h4>
    <p>Any code used for tracking purposes that is placed in the header goes here</p>
    <input type="text" name="analytics_code">


    <?php
    $site_logo = get_option("where_now_site_logo");

    if (isset($_POST["update_settings"])) {

    $site_logo = esc_attr($_POST["site_logo"]); 
update_option("where_now_site_logo", $site_logo);
?>
<div id="message" class="updated">Your Changes Have Been Saved</div>
<?php

}
    ?>
    <input type="hidden" name="update_settings" value="Y" />

    <input type="submit" value="Save settings" class="button-primary"/>
</form>
</div>
<?php    
}
?>

有什么想法吗?

【问题讨论】:

    标签: php html wordpress web


    【解决方案1】:

    我推荐你使用这个插件:Option Tree 它非常简单,不需要任何编码。只需将其安装在您的主题正在运行的网站上,然后您就可以轻松管理您的选项。

    【讨论】:

    • 我会调查的,但我正在为制作客户网站制作一个基本主题。我宁愿只编码。
    • 我想这可能对你有帮助Options Framework
    猜你喜欢
    • 1970-01-01
    • 2017-09-04
    • 1970-01-01
    • 2014-04-04
    • 1970-01-01
    • 1970-01-01
    • 2012-08-13
    • 2014-12-17
    • 2013-03-20
    相关资源
    最近更新 更多