让我们尝试以下代码
function sidebar_widget_init()
{
global $_wp_sidebars_widgets;
if ( empty( $_wp_sidebars_widgets ) ) :
$_wp_sidebars_widgets = get_option( \'sidebars_widgets\', array() );
endif;
$sidebars_widgets_count = $_wp_sidebars_widgets;
$sidebar_count = count( $sidebars_widgets_count[ \'sidebar3\' ] );
if($sidebar_count == 2){
$sidebar_class = \'class_name1\';
} elseif($sidebar_count == 3){
$sidebar_class = \'class_name2\';
} elseif($sidebar_count == 4){
$sidebar_class = \'class_name3\';
}
register_sidebar(array( \'name\' => __( \'Sidebar Footer\', \'templatemesh\' ),
\'id\' => \'sidebar3\',
\'description\' => __( \'Widgets in this area will be shown on footer Sidebar.\', \'templatemesh\' ),
\'before_title\' => \'<h3 class="widget_title">\',
\'after_title\' => \'</h3>\',
\'before_widget\' => \'<div class="\'.$sidebar_class.\'"><div id="%1$s" class="widget %2$s" >\',
\'after_widget\' => \'</div></div>\'
)
);
}
add_action(\'widgets_init\',\'sidebar_widget_init\');