开发者

Adding Additional Sidebar To Wordpress

I'm trying to add another sidebar to my Wordpress theme (Titan - http://wordpress.org/extend/themes/titan), but it seems to be a little more advanced than the themes being used in the tutorials.

I've been following this guide http://www.blogohblog.com/adding-extra-sidebar-to-your-wordpress-theme/

My Functions.php looks like this

<?php
    locate_template( array( 'functions' . DIRECTORY_SEPARATOR . 'titan-extend.php' ), true );

And the relevant block titan-extend.php file that I've been hacking away at looks like this

    /*---------------------------------------------------------
        6. Register Sidebars
    ------------------------------------------------------------ */
    function registerSidebars() {
        register_sidebar(array(
            'name' => __( 'Sidebar', 'titan' ),
            'id' => 'normal_sidebar',
            'before_widget' => '<li id="%1$s" class="widget %2$s">',
            'after_widget' => '</li>',
            'before_title' => '<h2 class="widgettitle">',
            'after_title' => '</h2>',
        ));
        register_sidebar(array(
            'name' => 'sidebar2'));
            'id' => 'sidebar2'
            'before_widget' => '<li id="%1$s" class="widget %2$s">',
            'after_widget' => '</li>',
            'before_title' => '<h2 class="widgettitle">',
            'after_title' => '</h2>',
    ));

    }

The current error I'm getting is Fatal error: Cannot redeclare Titan::开发者_JS百科registerSidebars() in /wp-content/themes/titan/functions/titan-extend.php on line 121

That's all the info I have, any and all help is appreciated


The tutorial your referring to is outdated and doesn't user WordPress best practices.

The proper way to register sidebar is to create a register function then hook it into widgets_init

in your functions.php file add this:

add_action( 'widgets_init', 'sydeberz_register_sidebar' );
function sydeberz_register_sidebar() {
 register_sidebar(
    array(
        'name' => 'sidebar2',
        'id' => 'sidebar2',
        'before_widget' => '<li id="%1$s" class="widget %2$s">',
        'after_widget' => '</li>',
        'before_title' => '<h2 class="widgettitle">',
        'after_title' => '</h2>',
));

}

See Justin Tadlock's Sidebars in WordPress post.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜