如何添加多个页脚控件?

时间:2020-07-17 作者:Developer

我是WordPress的新手。我现在使用的是2017年的主题。我想添加多个页脚小部件,但是WordPress限制我只能添加两个。是否可以再添加几个页脚小部件?如果是,我该怎么做?我花了两天时间在互联网上搜索有用的答案。

我更喜欢PHP或CSS文件修改答案。

提前谢谢你。。。

I need to add multiple footers like these..

1 个回复
SO网友:Younes.D

页脚1和页脚2是边栏,您可以在其中添加自己的边栏functions.php 或创建子主题:

function twentyseventeen_widgets_init() {
register_sidebar( array(
    \'name\'          => __( \'Blog Sidebar\', \'twentyseventeen\' ),
    \'id\'            => \'sidebar-1\',
    \'description\'   => __( \'Add widgets here to appear in your sidebar on blog posts and archive pages.\', \'twentyseventeen\' ),
    \'before_widget\' => \'<section id="%1$s" class="widget %2$s">\',
    \'after_widget\'  => \'</section>\',
    \'before_title\'  => \'<h2 class="widget-title">\',
    \'after_title\'   => \'</h2>\',
) );

register_sidebar( array(
    \'name\'          => __( \'Footer 1\', \'twentyseventeen\' ),
    \'id\'            => \'sidebar-2\',
    \'description\'   => __( \'Add widgets here to appear in your footer.\', \'twentyseventeen\' ),
    \'before_widget\' => \'<section id="%1$s" class="widget %2$s">\',
    \'after_widget\'  => \'</section>\',
    \'before_title\'  => \'<h2 class="widget-title">\',
    \'after_title\'   => \'</h2>\',
) );

register_sidebar( array(
    \'name\'          => __( \'Footer 2\', \'twentyseventeen\' ),
    \'id\'            => \'sidebar-3\',
    \'description\'   => __( \'Add widgets here to appear in your footer.\', \'twentyseventeen\' ),
    \'before_widget\' => \'<section id="%1$s" class="widget %2$s">\',
    \'after_widget\'  => \'</section>\',
    \'before_title\'  => \'<h2 class="widget-title">\',
    \'after_title\'   => \'</h2>\',
) );
}
add_action( \'widgets_init\', \'twentyseventeen_widgets_init\' );
您可以通过拖放小部件来添加任意数量的小部件。中显示的模板twentyseventeen/template-parts/footer/footer-widgets.php

<?php
 if ( is_active_sidebar( \'sidebar-2\' ) ||
 is_active_sidebar( \'sidebar-3\' ) ) :
?>

<aside class="widget-area" role="complementary" aria-label="<?php esc_attr_e( \'Footer\', \'twentyseventeen\' ); ?>">
    <?php
    if ( is_active_sidebar( \'sidebar-2\' ) ) { ?>
        <div class="widget-column footer-widget-1">
            <?php dynamic_sidebar( \'sidebar-2\' ); ?>
        </div>
    <?php }
    if ( is_active_sidebar( \'sidebar-3\' ) ) { ?>
        <div class="widget-column footer-widget-2">
            <?php dynamic_sidebar( \'sidebar-3\' ); ?>
        </div>
    <?php } ?>
</aside><!-- .widget-area -->

<?php endif; ?>

相关推荐

My widgets do not save

每次我保存我的小部件并离开页面时,我的小部件都会消失。侧边栏已完全清空,不会保存任何更改。控制台或PHP日志中没有任何错误。如果我将小部件直接复制并保存在数据库中widgets_text, 它们将被显示,但我仍然无法在侧边栏中添加或删除任何内容。这只发生在我的右侧边栏上,左侧边栏工作正常,但它们都以相同的方式注册。这是我注册侧边栏的方式:function my_widgets_init() { register_sidebar( array ( \'name\'