dougang1605 2011-05-14 02:16
浏览 30
已采纳

添加附加边栏到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::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

  • 写回答

1条回答 默认 最新

  • dongxiaoyan4388 2011-05-14 02:43
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于知识的学以致用的解释
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败