【问题标题】:Adding Additional Sidebar To Wordpress向 Wordpress 添加附加边栏
【发布时间】:2011-05-14 02:16:39
【问题描述】:

我正在尝试为我的 Wordpress 主题(Titan - http://wordpress.org/extend/themes/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()

这就是我所拥有的所有信息,感谢任何和所有帮助

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    您所指的教程已经过时,并且没有使用 WordPress 最佳实践。

    注册侧边栏的正确方法是创建一个注册函数,然后将其挂接到widgets_init

    在你的functions.php文件中添加这个:

    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>',
    ));
    
    }
    

    查看 Justin Tadlock 的 Sidebars in WordPress 帖子。

    【讨论】:

    • 修复了错误,但是在包含 进入page.php并浏览了一个页面
    • &lt;?php dynamic_sidebar( 'sidebar2' ); ?&gt;
    • 知道了!谢谢@Chris_O,现在有什么将它与另一边对齐的提示吗? Sidebar2.php 包含 &lt;div id="sidebar2"&gt; &lt;?php dynamic_sidebar( 'sidebar2' ); ?&gt; &lt;/div&gt; 我已将其添加到我的 css 文件中`#sidebar2 {float:left;padding-bottom:30px;width:100px;}` 但它不会去任何地方...
    猜你喜欢
    • 1970-01-01
    • 2013-11-24
    • 2020-10-22
    • 1970-01-01
    • 2015-04-09
    • 1970-01-01
    • 2018-04-24
    • 1970-01-01
    • 2017-09-09
    相关资源
    最近更新 更多