注册侧边栏

1
2
3
4
5
6
7
8
9
10
11
12
13
14
add_action( 'widgets_init', 'theme_slug_widgets_init' );
function theme_slug_widgets_init() {
register_sidebar( array(
'name' => 'Main Sidebar',
'id' => 'sidebar-1',
'description' => __( 'Widgets in this area will be shown on all posts and pages.', 'theme-slug' ),
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
) );
}

register_sidebar(1, array('name'=> 'sidebarname', 'id' => 'sidebarid' ));

自定义侧边栏调用

判断不同页面调用不同的侧边栏

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php if ( is_active_sidebar('footer-1') || is_active_sidebar('footer-2') || is_active_sidebar('footer-3') ) : ?>
<?php
if ( is_active_sidebar( 'footer-1' ) ) : ?>
<div class="footer-column">
<?php dynamic_sidebar( 'footer-1'); ?>
</div>
<?php endif;
if ( is_active_sidebar( 'footer-2' ) ) : ?>
<div class="footer-column">
<?php dynamic_sidebar( 'footer-2'); ?>
</div>
<?php endif;
if ( is_active_sidebar( 'footer-3' ) ) : ?>
<div class="footer-column"> <?php
dynamic_sidebar( 'footer-3'); ?>
</div>
<?php endif;
if ( is_active_sidebar( 'footer-4' ) ) : ?>
<div class="footer-column"> <?php
dynamic_sidebar( 'footer-4'); ?>
</div>
<?php endif; ?>
<?php endif; ?>