注册的 WordPress 侧边栏不显示
Registered WordPress Sidebar not showing
我在 WordPress 中有一个侧边栏,我是这样注册的:
register_sidebar(array(
'id' => '404',
'name' => __('404', 'jointstheme'),
'description' => __('The 404 sidebar.', 'jointstheme'),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widgettitle">',
'after_title' => '</h4>',
));
我复制了现有的 'sidebar.php' 文件并创建了一个名为:sidebar-404.php.
的文件
我还在 404 页面模板中添加了对侧边栏的调用,如下所示:
<?php get_sidebar('404'); ?>
但出于某种原因,我的主题一直默认为默认边栏。
有人知道会发生什么吗?
谢谢!
当您在 functions.php
文件中注册侧边栏并希望在管理面板中使用小部件管理器时,您需要使用 dynamic siderbars 而不是 get_sidebar
。 get_sidebar
将仅显示编码到文件中的小部件。
而不是 <?php get_sidebar('404'); ?>
你应该有 <?php dynamic_sidebar( '404' ); ?>
我在 WordPress 中有一个侧边栏,我是这样注册的:
register_sidebar(array(
'id' => '404',
'name' => __('404', 'jointstheme'),
'description' => __('The 404 sidebar.', 'jointstheme'),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widgettitle">',
'after_title' => '</h4>',
));
我复制了现有的 'sidebar.php' 文件并创建了一个名为:sidebar-404.php.
的文件我还在 404 页面模板中添加了对侧边栏的调用,如下所示:
<?php get_sidebar('404'); ?>
但出于某种原因,我的主题一直默认为默认边栏。
有人知道会发生什么吗?
谢谢!
当您在 functions.php
文件中注册侧边栏并希望在管理面板中使用小部件管理器时,您需要使用 dynamic siderbars 而不是 get_sidebar
。 get_sidebar
将仅显示编码到文件中的小部件。
而不是 <?php get_sidebar('404'); ?>
你应该有 <?php dynamic_sidebar( '404' ); ?>