Wordpress - 如何显示自定义小部件

时间:2011-11-09 22:17:03

标签: wordpress

我是wordpress的新手。我想创建自己的自定义小部件并在侧面菜单上显示内容。但是,即使wordpress显示在wordpress的控制面板中,它也不显示小部件。我将CustomWidget添加到主窗口小部件区域。

编辑:我注意到“小部件”功能没有被调用,因为它假设是进行渲染的那个。

class CustomWidget extends WP_Widget{
    function CustomWidget(){
        $widget_ops = array('classname' => 'custom_widget', 'description' => __( "Custom Widget") );
        $control_ops = array('width' => 250, 'height' => 400, 'id_base' => 'custom-widget');
        $this->WP_Widget('CustomWidget', 'Custom Widget', $widget_ops, $control_ops);
    }

    function widget($args, $instance){
        extract($args);
        $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title']);
        $menu_order = $instance['menu_order'];
        $show_siblings = $instance['show_siblings'];
        $exclude = $instance['exclude'];
        echo $before_widget;
        echo $before_title;
        echo 'Title!!!';
        echo $after_title;
        echo 'Content!!!';
        echo $after_widget;
    }
}

function CustomWidget_init(){
    register_widget('CustomWidget');
}
add_action("widgets_init", "CustomWidget_init");

1 个答案:

答案 0 :(得分:0)

在代码末尾添加此内容

add_action('TB_RenderWidget', array('CustomWidget', 'render'),10,12 );
相关问题