Archive | Wordpress
Creating a simple widget in WordPress
Aug 25th, 2011No Comments
We have a standard format in WP for creating a simple WordPress widget .
- You need to create a Class Which Extends Wp_Widget .
class YOURPLUGINNAME extends WP_Widget { ..... ... } - There are some predefined methods to be used in php .
- widget method : The code or content written in it is displayed in front-end , this method looks like ..
function widget($args, $instance) { }
- widget method : The code or content written in it is displayed in front-end , this method looks like ..
- The Simple widget Class looks like this .
class YOURPLUGINNAME extends WP_Widget { /** constructor */ function YOURPLUGINNAME() { $widget_ops = array ( 'description' => __('Description of the widget goes here') ); parent :: WP_Widget(false, $name = 'Name of the widget', $widget_ops); } /** @see WP_Widget::widget */ function widget($args, $instance) { } /** @see WP_Widget::update */ function update($new_instance, $old_instance) { $instance = $old_instance; $instance['title'] = strip_tags($new_instance['title']); $instance['email'] = strip_tags($new_instance['email']); $instance['from'] = strip_tags($new_instance['from']); return $instance; } /** @see WP_Widget::form */ function form($instance) { } } - Finally you need to register the Class for widget creation .
add_action('widgets_init', create_function('', 'return register_widget("YOURPLUGINNAME");'));
Yep.... I couldn't have said it better myself......
Yep.... I couldn't have said it better myself......
Yahoo results... While searching Yahoo I found this page in the results and I didn't think
Nice Focus.... I really like the direction you've decided to take this blog....