[英]Enabling sidebar in my wordpress theme
Hey guys am coding a wordpress theme from scratch ..I need to enable a side bar on the right side of my theme. 大家好,我是从头开始编写wordpress主题的。我需要在主题的右侧启用侧边栏。
So in my functions.php
i have enabled some code like 因此,在我的functions.php
我启用了一些代码,例如
function arphabet_widgets_init() {
register_sidebar( array(
'name' => 'The sidebar',
'id' => 'home_right_1',
'before_widget' => '<div>',
'after_widget' => '</div>',
'before_title' => '<h2 class="rounded">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'arphabet_widgets_init' );
In my sidebar.php
在我的sidebar.php
<?php if ( is_active_sidebar( 'sidebar-1' ) ) : ?>
<div id="secondary" class="widget-area" role="complementary">
<?php dynamic_sidebar( 'sidebar-1' ); ?>
</div><!-- #secondary -->
<?php endif; ?>
In the style.css
在style.css
.widget-area {
float:right;
width:330px;
}
But when i run the code the sidebar isnt displaying.I just want to display the sidebar on the right side of my theme page. 但是当我运行代码时,侧栏不会显示。我只想在主题页面的右侧显示侧栏。
Thanx in advance 提前感谢
I think you must use Name or ID of dynamic sidebar 我认为您必须使用动态边栏的名称或ID
<?php if ( is_active_sidebar( 'home_right_1' ) ) : ?>
<div id="secondary" class="widget-area" role="complementary">
<?php dynamic_sidebar( 'home_right_1' ); ?>
</div>
<?php endif; ?>
And use this function 并使用此功能
if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'name' => __('Main sidebar', 'framewrok'),
'id' => 'home_right_1',
'description' => __('Default main sidebar.', 'framework'),
'before_widget' => '<div class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<div class="widget-title"><h2>',
'after_title' => '</h2></div>'
));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.