2015-05-04 29 views
0

我在我的Wordpress小工具中有這2個功能,但我無法獲得窗體功能來獲取窗口小部件選項的默認值或保存值。WordPress的小工具窗體功能

private static function get_defaults() { 
    $defauls = array(
      'title' => '' , 
      'subtitle' => '' , 
      'columns' => '4' , 
      'ntax' => '' , 
      'showposts' => '12' , 
      'imagesize' => 'medium' , 
      'posttype' => '' , 
      'exclude' => '' , 
      'terms' => '' , 
      'border' => '' , 
      'padding' => '' 
     ); 

    return $defaults; 
} 
/** 
* Generates the administration form for the widget. 
* 
* @param array instance The array of keys and values for the widget. 
*/ 
public function form($instance) { 
    $instance = wp_parse_args(
     (array)$instance,self::get_defaults() 
    ); 

回答

0

我不明白你要達到的效果,但要建立一個部件,請按照Widget API

要獲取特定小部件「選項」/屬性的值,您必須使用$instance。例如,你想獲得小部件的標題:

$instance['title'] 

如果你想獲得的形式功能控件的名稱,用途:

/** 
* Generates the administration form for the widget. 
* 
* @param array instance The array of keys and values for the widget. 
*/ 
public function form($instance) { 
    $title = ! empty($instance['title']) ? $instance['title'] : __('New title', 'text_domain'); 
); 

什麼你」重新做,而是用一些參數覆蓋$instance

要了解更多信息,請考慮做一些教程:

1: How To Build WordPress Widgets Like A Pro

2: How to Create a Custom WordPress Widget