オリジナルのウィジェットを作成する

Ads

Code

<?php
add_action("widgets_init", array('my_widget_name', 'register'));
class my_widget_name {
function control(){
echo 'ここに設定項目を入れる';
}
function widget($args){
echo $args['before_widget'];
echo $args['before_title'] . 'ウィジェットのタイトル' . $args['after_title'];
echo 'I am your widget';
echo $args['after_widget'];
}
function register(){
register_sidebar_widget('ウィジェット名', array('my_widget_name', 'widget'));
register_widget_control('ウィジェット名', array('my_widget_name', 'control'));
}
}
?>
view raw gistfile1.aw hosted with ❤ by GitHub

Screen shot

Note

Description オリジナルのウィジェットを作成するための基本コード
WordPress Ver. 3.3.1
Via register a widget in function.php