wordpress模板修改-自定义侧边栏(小工具)插件显示位置

先下载了一个模板挺漂亮,可惜不支持侧边栏(小工具)插件,研究了下模板代码,自己给他添加个

第一步 : 找到 模板下面的 functions.php 文件 增加下面代码:<!–more–>

add_action('widgets_init', 'my_register_sidebars');
function my_register_sidebars() {
    register_sidebar(
        array(
            'id' => 'primary',
            'name' => __( 'Sidebar' ),
            'description' => __('Right sidebar.'),
            'before_widget' => '<div id="%1$s" class="widget %2$s">',
            'after_widget' => '</div>',
            'before_title' => '<h3>',
            'after_title' => '</h3>'
        )
    );
}

第二步 : 在模板文件相应位置插入:

<?php if ( is_active_sidebar( 'secondary-widget-area' ) ) : ?>
<?php dynamic_sidebar( 'secondary-widget-area' ); ?>
<?php endif; ?>

Tags: ,

Leave a comment

You must be logged in to post a comment.