注册侧边栏

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' => '
  • ',

  • 'after_widget' => '',
    'before_title' => '

    ',


    'after_title' => '',
    ) );
    }

    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


    if ( is_active_sidebar( 'footer-1' ) ) : ?>




    if ( is_active_sidebar( 'footer-2' ) ) : ?>




    if ( is_active_sidebar( 'footer-3' ) ) : ?>


    if ( is_active_sidebar( 'footer-4' ) ) : ?>