Create wordpress custom widget

代码放到 functions.php 就可以在小工具里获得该 widget。



class weibo_widget extends WP_Widget {

    public function __construct() {
        // widget actual processes 
        //get_popular_resource
        parent::__construct(
                'weibo_widget', // Base ID
                'Weibo widget', // Name
                array('description' => __('Weibo Widget', 'affc'),) // Args
        );
    }

    public function form($instance) {
        // outputs the options form on admin
        if (isset($instance['weibo_uid'])) {
            $weibo_uid = $instance['weibo_uid'];
        } else {
            $weibo_uid = __('Weibo UID', 'affc');
        }
        if (isset($instance['weibo_verifier'])) {
            $weibo_verifier = $instance['weibo_verifier'];
        } else {
            $weibo_verifier = __('Weibo UID', 'affc');
        }        
        ?>