繁体   English   中英

在我的wordpress主题中启用侧边栏

[英]Enabling sidebar in my wordpress theme

大家好,我是从头开始编写wordpress主题的。我需要在主题的右侧启用侧边栏。

因此,在我的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' );

在我的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; ?>

style.css

.widget-area {
float:right;
width:330px;
}

但是当我运行代码时,侧栏不会显示。我只想在主题页面的右侧显示侧栏。

提前感谢

我认为您必须使用动态边栏的名称或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; ?>

并使用此功能

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM