get_option('widget_archives') ); $sidebars[$k][$key] = 'archive_widget-1'; update_option('sidebars_widgets', $sidebars); break; } elseif ( ( $key = array_search('Archives', $sidebars[$k]) ) !== false ) { $options = array( 1 => get_option('widget_archives') ); $sidebars[$k][$key] = 'archive_widget-1'; update_option('sidebars_widgets', $sidebars); break; } } update_option('archive_widgets', $options); } $widget_options = array('classname' => 'archives', 'description' => __( "Archives Widget") ); $control_options = array('width' => 300, 'id_base' => 'archive_widget'); $id = false; # registered widgets foreach ( array_keys($options) as $o ) { if ( !is_numeric($o) ) continue; $id = "archive_widget-$o"; wp_register_sidebar_widget($id, __('Archives'), array('archive_widgets', 'widget_archives'), $widget_options, array( 'number' => $o )); wp_register_widget_control($id, __('Archives'), array('archive_widgets_admin', 'widget_archives_control'), $control_options, array( 'number' => $o ) ); } # default widget if none were registered if ( !$id ) { $id = "archive_widget-1"; wp_register_sidebar_widget($id, __('Archives'), array('archive_widgets', 'widget_archives'), $widget_options, array( 'number' => -1 )); wp_register_widget_control($id, __('Archives'), array('archive_widgets_admin', 'widget_archives_control'), $control_options, array( 'number' => -1 ) ); } } # widgetize() # # widget_archives() # function widget_archives($args, $widget_args = 1) { extract($args, EXTR_SKIP); if ( is_numeric($widget_args) ) $widget_args = array( 'number' => $widget_args ); $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) ); extract( $widget_args, EXTR_SKIP ); $options = get_option('archive_widgets'); if ( !isset($options[$number]) ) return; $count = $options[$number]['count'] ? '1' : '0'; $dropdown = $options[$number]['dropdown'] ? '1' : '0'; $title = empty($options[$number]['title']) ? __('Archives') : $options[$number]['title']; if ( is_admin() ) { echo $before_widget . $before_title . $title . $after_title . $after_widget; return; } echo $before_widget . "\n" . ( trim($title) !== '' ? ( $before_title . $title . $after_title . "\n" ) : '' ); if($dropdown) { echo ''; } else { echo '