saturngod
saturngod

Reputation: 24967

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_widget_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.

Upvotes: 1

Views: 177

Answers (2)

awats
awats

Reputation: 447

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/

Upvotes: 0

Chris_O
Chris_O

Reputation: 3444

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

Upvotes: 1

Related Questions