2010-11-18 88 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/