开发者

More than 1 widget in wordpress

Following is my code

$op=array("description"=>"Ads Widget");
    wp_register_sidebar_widget('adswidget','Ads','ads_widget',$op);
    register_widge开发者_StackOverflowt_control('adswidget','ads_widget_control');

I can use only 1 Ads Widget. I want to use more than 1 Ads Widget ? How to write it ? I'm finding in google and still not found.

Still not found document on

http://codex.wordpress.org/Function_Reference/wp_register_sidebar_widget

also.


By default all widgets that are created using the widgets api are multi instance.

The code you have above is the old method before WordPress 2.8. Now you just need to extend the widget class and add some functions. Default Example:

class My_Widget extends WP_Widget {
function My_Widget() {
    // widget actual processes
}

function form($instance) {
    // outputs the options form on admin
}

function update($new_instance, $old_instance) {
    // processes widget options to be saved
}

function widget($args, $instance) {
    // outputs the content of the widget
}

}
register_widget('My_Widget');

See Codex Page: http://codex.wordpress.org/Plugins/WordPress_Widgets_Api


I like the solution above as it's much simpler and easier to implement, but here is another method of multi-widgets which sort of provides a behind the scenes look as well...

http://justcoded.com/article/wordpress-multi-widgets/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜