Add support for multiple instances of the category widget. see #4285
git-svn-id: http://svn.automattic.com/wordpress/branches/2.2@5669 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
d987e188d7
commit
cb975258ca
|
@ -609,20 +609,20 @@ function wp_widget_text_register() {
|
||||||
add_action('sidebar_admin_page', 'wp_widget_text_page');
|
add_action('sidebar_admin_page', 'wp_widget_text_page');
|
||||||
}
|
}
|
||||||
|
|
||||||
function wp_widget_categories($args) {
|
function wp_widget_categories($args, $number = 1) {
|
||||||
extract($args);
|
extract($args);
|
||||||
$options = get_option('widget_categories');
|
$options = get_option('widget_categories');
|
||||||
$c = $options['count'] ? '1' : '0';
|
$c = $options[$number]['count'] ? '1' : '0';
|
||||||
$h = $options['hierarchical'] ? '1' : '0';
|
$h = $options[$number]['hierarchical'] ? '1' : '0';
|
||||||
$d = $options['dropdown'] ? '1' : '0';
|
$d = $options[$number]['dropdown'] ? '1' : '0';
|
||||||
$title = empty($options['title']) ? __('Categories') : $options['title'];
|
$title = empty($options[$number]['title']) ? __('Categories') : $options[$number]['title'];
|
||||||
|
|
||||||
echo $before_widget;
|
echo $before_widget;
|
||||||
echo $before_title . $title . $after_title;
|
echo $before_title . $title . $after_title;
|
||||||
|
|
||||||
$cat_args = "orderby=name&show_count={$c}&hierarchical={$h}";
|
$cat_args = "orderby=name&show_count={$c}&hierarchical={$h}";
|
||||||
|
|
||||||
if($d) {
|
if ( $d ) {
|
||||||
wp_dropdown_categories($cat_args . '&show_option_none= ' . __('Select Category'));
|
wp_dropdown_categories($cat_args . '&show_option_none= ' . __('Select Category'));
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
@ -648,22 +648,29 @@ function wp_widget_categories($args) {
|
||||||
echo $after_widget;
|
echo $after_widget;
|
||||||
}
|
}
|
||||||
|
|
||||||
function wp_widget_categories_control() {
|
function wp_widget_categories_control( $number ) {
|
||||||
$options = $newoptions = get_option('widget_categories');
|
$options = $newoptions = get_option('widget_categories');
|
||||||
if ( $_POST['categories-submit'] ) {
|
|
||||||
$newoptions['count'] = isset($_POST['categories-count']);
|
if ( !is_array( $options ) ) {
|
||||||
$newoptions['hierarchical'] = isset($_POST['categories-hierarchical']);
|
$options = $newoptions = get_option( 'widget_categories' );
|
||||||
$newoptions['dropdown'] = isset($_POST['categories-dropdown']);
|
|
||||||
$newoptions['title'] = strip_tags(stripslashes($_POST['categories-title']));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( $_POST['categories-submit-' . $number] ) {
|
||||||
|
$newoptions[$number]['count'] = isset($_POST['categories-count-' . $number]);
|
||||||
|
$newoptions[$number]['hierarchical'] = isset($_POST['categories-hierarchical-' . $number]);
|
||||||
|
$newoptions[$number]['dropdown'] = isset($_POST['categories-dropdown-' . $number]);
|
||||||
|
$newoptions[$number]['title'] = strip_tags(stripslashes($_POST['categories-title-' . $number]));
|
||||||
|
}
|
||||||
|
|
||||||
if ( $options != $newoptions ) {
|
if ( $options != $newoptions ) {
|
||||||
$options = $newoptions;
|
$options = $newoptions;
|
||||||
update_option('widget_categories', $options);
|
update_option('widget_categories', $options);
|
||||||
}
|
}
|
||||||
$count = $options['count'] ? 'checked="checked"' : '';
|
|
||||||
$hierarchical = $options['hierarchical'] ? 'checked="checked"' : '';
|
$count = $options[$number]['count'] ? 'checked="checked"' : '';
|
||||||
$dropdown = $options['dropdown'] ? 'checked="checked"' : '';
|
$hierarchical = $options[$number]['hierarchical'] ? 'checked="checked"' : '';
|
||||||
$title = attribute_escape($options['title']);
|
$dropdown = $options[$number]['dropdown'] ? 'checked="checked"' : '';
|
||||||
|
$title = attribute_escape($options[$number]['title']);
|
||||||
?>
|
?>
|
||||||
<p><label for="categories-title"><?php _e('Title:'); ?> <input style="width: 250px;" id="categories-title" name="categories-title" type="text" value="<?php echo $title; ?>" /></label></p>
|
<p><label for="categories-title"><?php _e('Title:'); ?> <input style="width: 250px;" id="categories-title" name="categories-title" type="text" value="<?php echo $title; ?>" /></label></p>
|
||||||
<p style="text-align:right;margin-right:40px;"><label for="categories-count"><?php _e('Show post counts'); ?> <input class="checkbox" type="checkbox" <?php echo $count; ?> id="categories-count" name="categories-count" /></label></p>
|
<p style="text-align:right;margin-right:40px;"><label for="categories-count"><?php _e('Show post counts'); ?> <input class="checkbox" type="checkbox" <?php echo $count; ?> id="categories-count" name="categories-count" /></label></p>
|
||||||
|
@ -673,6 +680,79 @@ function wp_widget_categories_control() {
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function wp_widget_categories_setup() {
|
||||||
|
$options = $newoptions = get_option( 'widget_categories' );
|
||||||
|
|
||||||
|
if ( isset( $_POST['categories-number-submit'] ) ) {
|
||||||
|
$number = (int) $_POST['categories-number'];
|
||||||
|
|
||||||
|
if ( $number > 9 ) {
|
||||||
|
$number = 9;
|
||||||
|
} elseif ( $number < 1 ) {
|
||||||
|
$number = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$newoptions['number'] = $number;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $newoptions != $options ) {
|
||||||
|
$options = $newoptions;
|
||||||
|
update_option( 'widget_categories', $options );
|
||||||
|
wp_widget_categories_register( $options['number'] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function wp_widget_categories_page() {
|
||||||
|
$options = get_option( 'widget_categories' );
|
||||||
|
?>
|
||||||
|
<div class="wrap">
|
||||||
|
<form method="post">
|
||||||
|
<h2><?php _e( 'Categories Widgets' ); ?></h2>
|
||||||
|
<p style="line-height: 30px;"><?php _e( 'How many categories widgets would you like?' ); ?>
|
||||||
|
<select id="categories-number" name="categories-number" value="<?php echo attribute_escape( $options['number'] ); ?>">
|
||||||
|
<?php
|
||||||
|
for ( $i = 1; $i < 10; $i++ ) {
|
||||||
|
echo '<option value="' . $i . '"' . ( $i == $options['number'] ? ' selected="selected"' : '' ) . '>' . $i . "</option>\n";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
<span class="submit">
|
||||||
|
<input type="submit" value="<?php echo attribute_escape( __( 'Save' ) ); ?>" id="categories-number-submit" name="categories-number-submit" />
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
function wp_widget_categories_register() {
|
||||||
|
$options = get_option( 'widget_categories' );
|
||||||
|
$number = (int) $options['number'];
|
||||||
|
|
||||||
|
if ( $number > 9 ) {
|
||||||
|
$number = 9;
|
||||||
|
} elseif ( $number < 1 ) {
|
||||||
|
$number = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$dims = array( 'width' => 460, 'height' => 350 );
|
||||||
|
$class = array( 'classname' => 'widget_catgories' );
|
||||||
|
|
||||||
|
for ( $i = 1; $i <= 9; $i++ ) {
|
||||||
|
$name = sprintf( __( 'Categories %d' ), $i );
|
||||||
|
$id = 'categories-' . $i;
|
||||||
|
|
||||||
|
$widget_callback = ( $i <= $number ) ? 'wp_widget_categories' : '';
|
||||||
|
$control_callback = ( $i <= $number ) ? 'wp_widget_categories_control' : '';
|
||||||
|
|
||||||
|
wp_register_sidebar_widget( $id, $name, $widget_callback, $class, $i );
|
||||||
|
wp_register_widget_control( $id, $name, $control_callback, $dims, $i );
|
||||||
|
}
|
||||||
|
|
||||||
|
add_action( 'sidebar_admin_setup', 'wp_widget_categories_setup' );
|
||||||
|
add_action( 'sidebar_admin_page', 'wp_widget_categories_page' );
|
||||||
|
}
|
||||||
|
|
||||||
function wp_widget_recent_entries($args) {
|
function wp_widget_recent_entries($args) {
|
||||||
if ( $output = wp_cache_get('widget_recent_entries') )
|
if ( $output = wp_cache_get('widget_recent_entries') )
|
||||||
return print($output);
|
return print($output);
|
||||||
|
@ -954,37 +1034,42 @@ function wp_widget_rss_register() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function wp_widgets_init() {
|
function wp_widgets_init() {
|
||||||
global $wp_register_widget_defaults;
|
$GLOBALS['wp_register_widget_defaults'] = true;
|
||||||
|
|
||||||
|
$dims90 = array( 'height' => 90, 'width' => 300 );
|
||||||
|
$dims100 = array( 'height' => 100, 'width' => 300 );
|
||||||
|
$dims150 = array( 'height' => 150, 'width' => 300 );
|
||||||
|
|
||||||
$wp_register_widget_defaults = true;
|
|
||||||
$dims90 = array('height' => 90, 'width' => 300);
|
|
||||||
$dims100 = array('height' => 100, 'width' => 300);
|
|
||||||
$dims150 = array('height' => 150, 'width' => 300);
|
|
||||||
$class = array('classname' => 'widget_pages');
|
$class = array('classname' => 'widget_pages');
|
||||||
wp_register_sidebar_widget('pages', __('Pages'), 'wp_widget_pages', $class);
|
wp_register_sidebar_widget('pages', __('Pages'), 'wp_widget_pages', $class);
|
||||||
wp_register_widget_control('pages', __('Pages'), 'wp_widget_pages_control', $dims150);
|
wp_register_widget_control('pages', __('Pages'), 'wp_widget_pages_control', $dims150);
|
||||||
|
|
||||||
$class['classname'] = 'widget_calendar';
|
$class['classname'] = 'widget_calendar';
|
||||||
wp_register_sidebar_widget('calendar', __('Calendar'), 'wp_widget_calendar', $class);
|
wp_register_sidebar_widget('calendar', __('Calendar'), 'wp_widget_calendar', $class);
|
||||||
wp_register_widget_control('calendar', __('Calendar'), 'wp_widget_calendar_control', $dims90);
|
wp_register_widget_control('calendar', __('Calendar'), 'wp_widget_calendar_control', $dims90);
|
||||||
|
|
||||||
$class['classname'] = 'widget_archives';
|
$class['classname'] = 'widget_archives';
|
||||||
wp_register_sidebar_widget('archives', __('Archives'), 'wp_widget_archives', $class);
|
wp_register_sidebar_widget('archives', __('Archives'), 'wp_widget_archives', $class);
|
||||||
wp_register_widget_control('archives', __('Archives'), 'wp_widget_archives_control', $dims100);
|
wp_register_widget_control('archives', __('Archives'), 'wp_widget_archives_control', $dims100);
|
||||||
|
|
||||||
$class['classname'] = 'widget_links';
|
$class['classname'] = 'widget_links';
|
||||||
wp_register_sidebar_widget('links', __('Links'), 'wp_widget_links', $class);
|
wp_register_sidebar_widget('links', __('Links'), 'wp_widget_links', $class);
|
||||||
|
|
||||||
$class['classname'] = 'widget_meta';
|
$class['classname'] = 'widget_meta';
|
||||||
wp_register_sidebar_widget('meta', __('Meta'), 'wp_widget_meta', $class);
|
wp_register_sidebar_widget('meta', __('Meta'), 'wp_widget_meta', $class);
|
||||||
wp_register_widget_control('meta', __('Meta'), 'wp_widget_meta_control', $dims90);
|
wp_register_widget_control('meta', __('Meta'), 'wp_widget_meta_control', $dims90);
|
||||||
|
|
||||||
$class['classname'] = 'widget_search';
|
$class['classname'] = 'widget_search';
|
||||||
wp_register_sidebar_widget('search', __('Search'), 'wp_widget_search', $class);
|
wp_register_sidebar_widget('search', __('Search'), 'wp_widget_search', $class);
|
||||||
$class['classname'] = 'widget_categories';
|
|
||||||
wp_register_sidebar_widget('categories', __('Categories'), 'wp_widget_categories', $class);
|
|
||||||
wp_register_widget_control('categories', __('Categories'), 'wp_widget_categories_control', $dims150);
|
|
||||||
$class['classname'] = 'widget_recent_entries';
|
$class['classname'] = 'widget_recent_entries';
|
||||||
wp_register_sidebar_widget('recent-posts', __('Recent Posts'), 'wp_widget_recent_entries', $class);
|
wp_register_sidebar_widget('recent-posts', __('Recent Posts'), 'wp_widget_recent_entries', $class);
|
||||||
wp_register_widget_control('recent-posts', __('Recent Posts'), 'wp_widget_recent_entries_control', $dims90);
|
wp_register_widget_control('recent-posts', __('Recent Posts'), 'wp_widget_recent_entries_control', $dims90);
|
||||||
|
|
||||||
wp_widget_text_register();
|
wp_widget_text_register();
|
||||||
wp_widget_rss_register();
|
wp_widget_rss_register();
|
||||||
wp_widget_recent_comments_register();
|
wp_widget_recent_comments_register();
|
||||||
|
wp_widget_categories_register();
|
||||||
|
|
||||||
$wp_register_widget_defaults = false;
|
$wp_register_widget_defaults = false;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue