简体   繁体   中英

Trying to setup widget sidebar with wordpress

/**
 * Register our sidebars and widgetized areas.
 *
 */
function arphabet_widgets_init() {

register_sidebar( array(
    'name' => 'Home right sidebar',
    'id' => 'home_right_1',
    'before_widget' => '<div id="index_right">',
    'after_widget' => '</div>',
    'before_title' => '<h2 class="small_title">',
    'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'arphabet_widgets_init' );

Alright I have been looking at the wiki for WordPress which says to throw this inside of the functions.php folder and I have done that.

<?php if ( is_active_sidebar( 'sidebar-1' ) ) : ?>
<div id="index_right" class="primary-sidebar widget-area" role="complementary">
<?php dynamic_sidebar( 'sidebar-1' ); ?>
</div><!-- #primary-sidebar -->
<?php endif; ?>
</div>

Then it says to include this file into your sidebar.php which I have also done how ever when I create a widget it displays as a blank space on the webpage.

在此处输入图片说明 On the image shown above I have placed a box around where the widget should be placed and I will also include my CSS for the div included and the h2 class included.

#index_right { 
width: 232px;
margin-left: 10px; 
float: left; }

.small_title { 
width: 222px;
height: 33px; 
padding-left: 10px; 
line-height: 36px; 
vertical-align: middle; 
background-image: url('images/bg_title.jpg'); 
background-position: left; text-align: left;
}

Contents within my sidebar.php file can be found here. - http://pastebin.com/gnVsh6MG

I think your problem is that you aren't actually calling the side bar you created. You are calling the sidebar with the id sidebar-1 , but you created one called home_right_1 . So changing:

<?php if ( is_active_sidebar( 'sidebar-1' ) ) : ?>
<div id="index_right" class="primary-sidebar widget-area" role="complementary">
<?php dynamic_sidebar( 'sidebar-1' ); ?>
</div><!-- #primary-sidebar -->
<?php endif; ?>
</div>

to

<?php if ( is_active_sidebar( 'home_right_1' ) ) : ?>
<div id="index_right" class="primary-sidebar widget-area" role="complementary">
<?php dynamic_sidebar( 'home_right_1' ); ?>
</div><!-- #primary-sidebar -->
<?php endif; ?>
</div>

should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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