我的小部件代码不能正常工作


My widget code is not working properly

我正在开发WordPress主题。我想展示的是小部件。在外观区域显示了我的小部件选项正确,但在主屏幕的小部件不显示正常。小部件区域在模板的右侧显示项目符号。请任何人帮助解决我的代码,并提及什么是错误??

我的代码
 register_sidebar(array(  
            'name'=> __('Right Hand Sidebar'),
            'id' => 'right-sidebar',
            'description' => __('Widgets in this area will be shown on the right-hand side'),
            'before_title' => '<h2>',
            'after_title' => '</h2>',
            'before_widget' => '<div id="%1$s" class="widget %2$s">',
            'after_widget' => '</div>'   
));
The below code need to add to theme's functions.php.Id should be unique.You need to hook your custom sidebar under widgets_init hook.
<?php 
function register_my_widgets(){
$args = array(
    'name'          => __( 'My Sidebar' ),
    'id'            => 'my-sidebar',
    'description'   => 'This is my sidebar',
        'class'         => '',
    'before_widget' => '<li id="%1$s" class="widget %2$s">',
    'after_widget'  => '</li>',
    'before_title'  => '<h2 class="widgettitle">',
    'after_title'   => '</h2>' ); 
     register_sidebar($args);
     }
     add_action( 'widgets_init', 'register_my_widgets' );
?>

After adding code you easily see your custom sidebar in Appearance->Widgets. Now you can add wordpress default widgets or you own.
To fetch the contents of this sidebar to frontend.You need to add the code below.
<?php 
if ( is_active_sidebar( 'my-sidebar' ) ){
    dynamic_sidebar('my-sidebar');
}
?>