【问题标题】:Include Sidebar Generator plug-in into my WP theme将 Sidebar Generator 插件包含到我的 WP 主题中
【发布时间】:2013-02-04 23:20:37
【问题描述】:

我正在尝试包含这个插件:

http://wordpress.org/extend/plugins/sidebar-generator/

进入我的 wordpress 主题。正如互联网上的许多人所说,我只是将 sidebar_generator.php 文件包含在我的 functions.php 中。 'Sidebars' 菜单出现在外观下,但无论我做什么,如果我点击它,什么都不会发生(就像它被链接在 '#' 上一样)。

如果我通过 wordpress 界面安装插件一切正常,但我需要集成它。

有什么帮助吗?

谢谢

【问题讨论】:

    标签: include wordpress sidebar


    【解决方案1】:

    您不需要插件来拥有额外的侧边栏。您应该能够构建带有任意数量侧边栏的主题模板。当我在 WordPress 中创建自定义主题时,我使用了 960 CSS Grid 的变体(另一个不错的是较新的 1140px CSS Grid System,它是流动的)。

    要注册您的侧边栏以接受小部件,请将此代码插入您的 functions.php 文件中:

    // Widget Areas //
    if ( function_exists('register_sidebars') ) {
        // Primary sidebar widget
        register_sidebar( array(
            'name' => __( 'Blog Sidebar', 'unique' ),
        'id' => 'blog-sidebar',
        'description' => __( 'The sidebar widget area for the blog.', 'unique' ),
        'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
        'after_widget' => '</li>',
        'before_title' => '<h2 class="widget-title">',
        'after_title' => '</h2>',
    ) );
    
    register_sidebar( array(
        'name' => __( 'Left Sidebar', 'unique' ),
        'id' => 'left-sidebar',
        'description' => __( 'The left sidebar widget area for pages.', 'unique' ),
        'before_widget' => '<li id="%1$s" class="greenGradient widget-container %2$s">',
        'after_widget' => '</li>',
        'before_title' => '<h2 class="widget-title greenbar center">',
        'after_title' => '</h2>',
    ) );
    
    register_sidebar( array(
        'name' => __( 'Right Sidebar', 'unique' ),
        'id' => 'right-sidebar',
        'description' => __( 'The right sidebar widget area for pages.', 'unique' ),
        'before_widget' => '<li id="%1$s" class="redGradient widget-container %2$s">',
        'after_widget' => '</li>',
        'before_title' => '<h2 class="widget-title redbar center">',
        'after_title' => '</h2>',
    ) );
    

    } 在这种情况下,我只为博客注册了一个侧边栏,然后为右侧边栏和左侧边栏分别注册了一个。

    在我的主题目录中,我有三个 sidebar.php 文件。博客侧边栏文件是默认的 sidebar.php 文件。另外两个被命名为sidebar-left.php 和sidebar-right.php。每个侧边栏都有相应的代码,如下所示:

       <?php // blog widget area
            if ( is_active_sidebar( 'blog-sidebar' ) ) : ?>
            <ul>
                <?php dynamic_sidebar( 'blog-sidebar' ); ?>
            </ul>
        <?php endif; // end blog widget area ?>
    

    将此代码包装在侧边栏中的 div 中,并确保将“博客侧边栏”名称更改为每个侧边栏的名称。

    【讨论】:

    • 感谢您的回复 HeatherFeuer。我想我被误解了。我知道如何硬编码和注册侧边栏,但我想要完成的是让用户无需编写任何代码就可以做到这一点,而是通过选项面板中的表单,就像 Sidebar Generator 允许你做的那样。问题是我无法正确地将其包含在我的主题中。
    • 好吧,我误会了!那么您要做的是提供像 Sufffusion 主题中的布局选项?
    • 我在本地服务器上的一个测试站点中安装了该插件,但无法使其与 TwentyTen 和最新版本的 WP 一起使用。我知道它应该如何工作。它已经两年多没有工作了,许可证几乎可以让你做任何你想做的事情。我的建议是让该代码正常工作并将其合并到您的主题中——感谢代码的原始作者。
    • 是的,脚本没有许可问题,即使它是一个已有 2 年历史的插件,我想它仍然是在主题中实现无限侧边栏功能的最简单解决方案。最后我可以让它工作并将其与选项框架集成。
    【解决方案2】:

    寻找函数admin_menu 并在该行进行编辑。只需将__FILE__ 替换为sidebar-generator

    解释:如果你使用侧边栏生成器作为插件,__FILE__ 表示sidebar-generator,但如果你将它包含在主题的某个目录中,常量__FILE__ 可能会更改为不同(例如 inc、includes... 或其他)

    【讨论】:

      猜你喜欢
      • 2016-03-31
      • 2015-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-23
      • 2016-02-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多