【问题标题】:How to Customize the Widgets in Wordpress如何在 Wordpress 中自定义小部件
【发布时间】:2011-09-04 11:22:40
【问题描述】:

我想删除外观/小部件中的一些小部件区域。我想删除“Primary Widget Area”、“Secondary Widget Area”和“Fourth Footer Widget Area”,这样用户就只能在 Appearance/Widgets 中看到其他三个 Footer Widget Area。

有没有办法做到这一点?

第二个问题是,我怎样才能只允许每个区域 1 个小部件。这样用户只能将 1 个小部件添加到我想在外观/小部件中显示的三个小部件区域中的几个小部件区域?

谢谢, 精们

【问题讨论】:

    标签: wordpress widget appearance


    【解决方案1】:

    小部件区域在您主题的functions.php 中分配。您应该找到以下内容:

    function the_widgets_init() {
        if ( !function_exists('register_sidebars') )
        return;
            register_sidebars(1,array('name' => 'Primary Widget Area',
            'before_widget' => '<div class="sidebar-item widget %2$s">',
            'after_widget' => '</div>',
            'before_title' => '<h2 class="widgettitle">','after_title' => '</h2>'));
            // ...
            // several instances of the above
            // ...
        }
    add_action( 'init', 'the_widgets_init' );
    

    删除您想要删除的任何小部件区域。

    另外,我相当肯定你不能限制每个区域的小部件数量,除非你愿意使用 wordpress 核心(这是不可取的,每次更新都会被覆盖)。

    【讨论】:

    • 谢谢,我已经通过使用 WP 的注销侧边栏功能完成了。现在一切正常,我的第二个问题并不那么重要,可以忽略。感谢您的帮助! :)
    猜你喜欢
    • 2012-11-20
    • 2011-12-25
    • 1970-01-01
    • 1970-01-01
    • 2020-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-10
    相关资源
    最近更新 更多