Jan 17, 2011
Add a personalized theme to the WordPress widget
Widgets We all know the background in the WordPress default generally comes in the category, text, calendar, recent comments that some small tools. But sometimes the personality for a WordPress theme, these default widgets obviously can not meet demand, so we need to customize some of the widgets for your topic. Now, let us see how to add your own WordPress theme widgets.
Add the following code in WordPress theme functions.php:
class widget_test extends WP_Widget {
function widget_test () {
$ Widget_ops = array ('description' => 'description of the small tools');
$ This-> WP_Widget ('widget_test', 'the title of the gadget', $ widget_ops);
}
function widget ($ args, $ instance) {
extract ($ args);
$ Title = apply_filters ('widget_title', esc_attr ($ instance ['title']));
$ Limit = strip_tags ($ instance ['limit']);
echo $ before_widget. $ before_title. $ title. $ after_title;
echo '<ul class="middleli">';
test ($ limit); / / function to be executed gadget
echo '</ ul>';
echo $ after_widget;
}
function update ($ new_instance, $ old_instance) {
if (! isset ($ new_instance ['submit'])) {
return false;
}
$ Instance = $ old_instance;
$ Instance ['title'] = strip_tags ($ new_instance ['title']);
$ Instance ['limit'] = strip_tags ($ new_instance ['limit']);
return $ instance;
}
function form ($ instance) {
global $ wpdb;
$ Instance = wp_parse_args ((array) $ instance, array ('title' =>'', 'limit' =>''));
$ Title = esc_attr ($ instance ['title']);
$ Limit = strip_tags ($ instance ['limit']);
?>
<p>
<Label for = "<? Php echo $ this-> get_field_id ('title');?>"> Title: <input class = "widefat" id = "<? Php echo $ this-> get_field_id ('title') ;?> "name =" <? php echo $ this-> get_field_name ('title');?> "type =" text "value =" <? php echo $ title;?> "/> </ label>
</ P>
<p>
<Label for = "<? Php echo $ this-> get_field_id ('limit');?>"> Quantity: <input class = "widefat" id = "<? Php echo $ this-> get_field_id ('limit') ;?> "name =" <? php echo $ this-> get_field_name ('limit');?> "type =" text "value =" <? php echo $ limit;?> "/> </ label>
</ P>
<Input type = "hidden" id = "<? Php echo $ this-> get_field_id ('submit');?>" Name = "<? Php echo $ this-> get_field_name ('submit');?>" Value = "1" />
<? Php
}
}
add_action ('widgets_init', 'widget_test_init');
function widget_test_init () {
register_widget ('widget_test');
}
Is the way to go after saving gadget in your look, is not more than one called "the gadget title of" the gadget you? Noted that the code above test ($ limit); this is a small tool you need to perform the function, you can write in here, you can also write to functions.php in function, are the same.
Maintained by BPOVIA Web Design Team





Recent Comments