Wordpress侧边栏不可见

In my footer.php I've added <?php get_sidebar('lj_sidebar'); ?> In my functions.php I've enabled widgets: add_theme_support('widgets'); and made a action hook add_action('widgets_init', 'lj_widgets');

Then in my widgets.php I make the widget like this:

<?php

function lj_widgets() {
    register_sidebar(array(
        'name'          => __('My First Theme Footer','lnj'),
        'id'            => 'lj_sidebar',
        'description'   => __('Footer for my first theme','lnj'),
        'class'         => '',
        'before_widget' => '<li id="%1$s" class="widget %2$s">',
        'after_widget'  => '</li>',
        'before_title'  => '<h2>',
        'after_title'   => '</h2>'
    ));
}

In my sidebar.php I check if the sidebar is enabled:

<?php

if(is_active_sidebar('lj_sidebar')) {
    dynamic_sidebar('lj_sidebar');
}

The widget is visible in my admin panel. But when I put for example a textfield in it. It's not showing up?

What am I doing wrong here?

When you call get_sidebar( 'lj_sidebar' );, WordPress is looking for the file sidebar-lj_sidebar.php and not sidebar.php.

You're calling your sidebar correctly with dynamic_sidebar( 'lj_sidebar' ); which says, "Display the widget area with the id lj_sidebar" but it's not displaying on the front-end because you're telling WordPresss to display the contents of sidebar-lj_sidebar.php which presumably doesn't exist.

Either:

  1. Rename your sidebar.php to sidebar-lj_sidebar.php, or
  2. Change your sidebar call from get_sidebar( 'lj_sidebar' ); to get_sidebar();.