之前,一直只喜欢单侧边栏,但最近一个客户需要添加双侧边栏,所以调查了一下怎么实现。
实现方法很简单,只需要在function.php
文件里添加定义,然后在sidebar.php
或者其它画面显示出来就行。
例,function.php
文件里在添加两个侧边栏。
if (function_exists('register_sidebar')) {
register_sidebar(array('name'=>'sidebar1',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h2>',
'after_title' => '</h2>',
));
register_sidebar(array('name'=>'sidebar2',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h2>',
'after_title' => '</h2>',
));
}
然后在要显示的地方,比如sidebar.php
里添加下面的代码就行。
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar1') ) : ?>
<?php endif; ?>
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar2') ) : ?>
<?php endif; ?>