2010-11-18 50 views
1

我想通过wp-admin> Appearance> Widgets中的选项面板来更改小工具的标题。WordPress的小工具选项保存不起作用

它似乎没有工作,点击“保存”后,它总是给出默认值,而不是保存的东西。

小工具的控制面板非常简单:

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;  
    } 

回答

0
  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');并echo $ this-> get_field_name('title');

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