我有一些PHP代码,我想从模板的现有页面中提取出来,然后放入一个小部件中,这样我就可以移动它了。
创建小部件的最快方法是什么?
我有一些PHP代码,我想从模板的现有页面中提取出来,然后放入一个小部件中,这样我就可以移动它了。
创建小部件的最快方法是什么?
这个Widgets API 是制作可重用小部件的最快方法。示例使用:
class My_Widget extends WP_Widget {
/**
* PHP4 constructor
*/
function My_Widget() {
My_Widget::__construct();
}
/**
* PHP5 constructor
*/
function __construct() {
// actual widget processes
}
/**
* Echo the settings update form
*
* @param array $instance Current settings
*/
function form($instance) {
// outputs the options form on admin
}
/**
* Update a particular instance
*
* @param array $new_instance New settings for this instance as input by the user via form()
* @param array $old_instance Old settings for this instance
* @return array Settings to save or bool (false) to cancel saving
*/
function update($new_instance, $old_instance) {
// processes widget options to be saved
}
/**
* Echo the widget content
*
* @param array $args Display arguments including before_title, after_title, before_widget, and after_widget
* @param array $instance The settings for the particular instance of this widget
*/
function widget($args, $instance) {
// outputs the content of the widget
}
}
register_widget(\'My_Widget\');
如果您不特别关心是否有合适的自定义小部件,可以使用如下插件PHP Code Widget 运行代码段
我对使用WordPress很陌生,我想知道使用小部件的好处是什么?看here 这听起来像是为那些不是程序员的人准备的,他们想在他们的网站上添加插件。对吗?或者小部件是否在某种程度上使站点更加健壮?