正确的方法是使用动态侧栏,它允许用户添加WordPress Widgets. 请参阅Codex entry on Widgetizing Themes.
基本上,您可以在中定义动态侧栏functions.php
; e、 g.:
<?php
function wpse45595_register_dynamic_sidebars() {
register_sidebar(array( // Top full-width widget area
\'name\'=>\'Main Sidebar\',
\'id\'=>\'sidebar-main\',
\'description\' => \'This is the main widget area for the Theme\',
\'before_widget\' => \'<div id="%1$s" class="widget %2$s">\',
\'after_widget\' => \'</div>\',
\'before_title\' => \'<div class="title widgettitle">\',
\'after_title\' => \'</div>\',
) );
}
add_action( \'widgets_init\', \'wpse45595_register_dynamic_sidebars\' );
?>
然后,在模板中的适当位置,例如
sidebar.php
, 您只需拨打:
<?php dynamic_sidebar( \'sidebar-main\' ); ?>
供参考: