窗口小部件未显示在WP面板中

时间:2018-11-29 18:47:58

标签: php wordpress

我正在为WP创建我的第一个插件。我有小部件,我想在侧边栏显示中显示我决定制作小部件。我做到了,但在WP面板中什么也没显示。

    <?php

//Klasa widgetu
class Skpp_Widget extends WP_Widget {
    //Konstruktor
    function __construct() {
        parent::__construct(
            'skpp_widget',
            'Widget SKPP',
            array( 'description' => 'Wyświetla jeden produkt' )
        );
    }

    //Główna funkcja widgetu
    public function widget( $args, $instance ) {
        echo 'test';
    }
}


//Rejetrujemy widget
function skpp_load_widget() {
    register_widget( 'skpp_widget' );
}

add_action( 'widgets_init', 'skpp_load_widget' );

1 个答案:

答案 0 :(得分:0)

function custom_widgets_init(){

register_sidebar(array(

    'name' => __( 'Main Sidebar', 'custom' ),

    'id' => 'sidebar-1',

    'description' => __( 'Appears on posts and pages except the optional Front Page template, which has its own widgets', 'custom' ),

    'before_widget' => '<aside id="%1$s" class="widget %2$s">',

    'after_widget' => '</aside>',

    'before_title' => '<h3 class="widget-title">',

    'after_title' => '</h3>',

) );

}

add_action('widgets_init','custom_widgets_init');