Php Wordpress控件窗体函数
我的Wordpress小部件中有这两个函数,但我无法获取表单函数来获取小部件选项的默认值或保存值Php Wordpress控件窗体函数,php,wordpress,widget,Php,Wordpress,Widget,我的Wordpress小部件中有这两个函数,但我无法获取表单函数来获取小部件选项的默认值或保存值 private static function get_defaults() { $defauls = array( 'title' => '' , 'subtitle' => '' , 'columns' => '4' , 'ntax' => '' ,
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()
);
我不明白你想实现什么,但要构建一个小部件,请遵循以下步骤 要获取特定小部件“option”/attribute的值,必须使用
$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
要了解更多,请考虑做一些教程: