【发布时间】:2016-08-17 03:02:10
【问题描述】:
在我的footer.php 中,我添加了<?php get_sidebar('lj_sidebar'); ?> 在我的functions.php 中,我启用了小部件:add_theme_support('widgets'); 并制作了一个动作挂钩add_action('widgets_init', 'lj_widgets');
然后在我的widgets.php 中制作这样的小部件:
<?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>'
));
}
在我的sidebar.php 中,我检查侧边栏是否已启用:
<?php
if(is_active_sidebar('lj_sidebar')) {
dynamic_sidebar('lj_sidebar');
}
小部件在我的管理面板中可见。但是当我在其中放置一个文本字段时。不显示?
我在这里做错了什么?
【问题讨论】:
-
这段代码没有问题。它对我来说工作正常。我们需要更多细节。
-
您可以使用此代码调用侧边栏中的小部件 if(is_active_sidebar('lj_sidebar')) { dynamic_sidebar('lj_sidebar'); }