【问题标题】:Wordpress Widget options saving doesn't workWordpress 小部件选项保存不起作用
【发布时间】:2010-11-18 17:47:08
【问题描述】:

我想通过 wp-admin > 外观 > 小部件中的选项面板获得可更改的小部件标题。

它似乎不起作用,点击“保存”后它总是返回默认值而不是保存东西。

Widgets 控制面板非常简单:

function myplugin_control() {

    echo '<p>
           <label for="myplugin_title">Title:</label>
           <input id="myplugin_title" name="myplugin_title" type="text" value="Default title:"/>
        </p>
        <p>
           <label for="myplugin_number">Number of items to show:</label>
           <input id="myplugin_number" name="myplugin_number" type="text" value="5" size="3"/>';  

        $myplugin_title = ($_POST["myplugin_title"]);
        $myplugin_number = ($_POST["myplugin_number"]);

        update_option('myplugin_widget', $myplugin_number , $myplugin_title); 

}

插件是这样的:

(...)
    function widget_myplugin($args) {
      extract($args);
      echo $before_widget;
      echo $before_title . $myplugin_title . $after_title;
      myplugin();
      echo $after_widget;     
    }

【问题讨论】:

    标签: wordpress widget


    【解决方案1】:
    1. 我认为您正在使用 update_option();不当。它只需要两个值。 http://codex.wordpress.org/Function_Reference/update_option

    2. 尝试将标题字段的名称更改为简单的“标题”。我认为 WP 默认会寻找这个;见:http://wordpress.org/support/topic/how-can-i-set-a-widgets-title-in-for-use-in-the-dashboard

    3. 不要使用 $_POST['title'],而是使用更标准的 $this->get_field_id('title');并回显 $this->get_field_name('title');

    希望这会有所帮助!另外:您可能会发现以下链接很有帮助:http://wpengineer.com/1023/wordpress-built-a-widget/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-26
      • 2012-08-13
      • 1970-01-01
      • 2015-11-14
      • 2014-09-30
      • 2014-08-02
      • 1970-01-01
      相关资源
      最近更新 更多