向 WordPress 添加附加侧边栏
我正在尝试向我的 WordPress 主题添加另一个侧边栏(Titan - http://wordpress.org/extend/ theme/titan),但它似乎比教程中使用的主题更高级一些。
我一直在关注这个指南 http://www.blogohblog.com/adding-extra- sidebar-to-your-wordpress-theme/
我的 Functions.php 看起来像这样
<?php
locate_template( array( 'functions' . DIRECTORY_SEPARATOR . 'titan-extend.php' ), true );
我一直在破解的相关块 titan-extend.php 文件看起来像这样
/*---------------------------------------------------------
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>',
));
}
我当前收到的错误是 致命错误:无法在第 121 行 /wp-content/themes/titan/functions/titan-extend.php 中重新声明 Titan::registerSidebars()
这就是我拥有的所有信息,所有帮助都是赞赏
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您引用的教程已经过时,并且没有使用 WordPress 最佳实践。
注册侧边栏的正确方法是创建一个注册函数,然后将其挂接到
functions.php文件中的
widgets_init
中,添加以下内容:请参阅Justin Tadlock的WordPress 中的侧边栏 帖子。
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:
See Justin Tadlock's Sidebars in WordPress post.