@Volomike,
当您在主题功能中注册侧栏时,它将在仪表板中处于活动状态。如果没有小部件添加到侧栏,WordPress将添加默认小部件。您可以通过取消注册来阻止WordPress添加默认小部件:
// Remove WP default Widgets
// WP 2.8 function using $widget_class
if (function_exists(\'unregister_widget\')) {
unregister_widget(\'WP_Widget_Meta\');
unregister_widget(\'WP_Widget_Search\');
unregister_widget(\'\');
// pre WP 2.8 function using $id
} else {
unregister_widget_control(\'meta\');
unregister_widget_control(\'search\');
}
您还可以预设自己的小部件。
// The following code sample is from The Thematic Theme which is licensed under the GPLv2
register_sidebar_widget(__(\'Search\', \'thematic\'), \'widget_thematic_search\', null, \'search\');
unregister_widget_control(\'search\');
register_sidebar_widget(__(\'Meta\', \'thematic\'), \'widget_thematic_meta\', null, \'meta\');
unregister_widget_control(\'meta\');
register_sidebar_widget(array(__(\'RSS Links\', \'thematic\'), \'widgets\'), \'widget_thematic_rsslinks\');
register_widget_control(array(__(\'RSS Links\', \'thematic\'), \'widgets\'), \'widget_thematic_rsslinks_control\', 300, 90);
// Pre-set Widgets
$preset_widgets = array (
\'primary-aside\' => array( \'search\', \'pages\', \'categories\', \'archives\' ),
\'secondary-aside\' => array( \'links\', \'rss-links\', \'meta\' )
);
if ( isset( $_GET[\'activated\'] ) ) {
update_option( \'sidebars_widgets\', apply_filters(\'thematic_preset_widgets\',$preset_widgets ));
}
Thematic is actually a great example of all the things that can be done with widgets. Take a look at widgets.php and widgets-extensions.php