AVH Extended Categories Widgets - Version 1.3

Version Description

Download this release

Release Info

Developer petervanderdoes
Plugin Icon wp plugin AVH Extended Categories Widgets
Version 1.3
Comparing to
See all releases

Code changes from version 1.2 to 1.3

Files changed (2) hide show
  1. readme.txt +7 -4
  2. widget_extended_categories.php +180 -125
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === Extended Categories Widget ===
2
- Contributors: petervanderdoes
3
  Donate link: http://blog.avirtualhome.com/wordpress-plugins/
4
  Tags: extended, categories, widget
5
  Requires at least: 2.3
6
- Tested up to: 2.5
7
- Stable tag: 1.2
8
 
9
  Replacement of the category widget to allow for greater customization of the category widget.
10
 
@@ -18,12 +18,13 @@ Replacement of the category widget to allow for greater customization of the cat
18
  * Show categories hierarchical.
19
  * Sort by ID, Name,Count.
20
  * Sort ascending or descending.
 
21
 
22
  == Installation ==
23
 
24
  The Extended Categories Widget can be installed in 3 easy steps:
25
 
26
- 1. Unzip "Extended Categories" archive and put the directory "extended-categories" into your "plugins" folder (wp-content/plugins/).
27
 
28
  1. Activate the plugin
29
 
@@ -39,6 +40,8 @@ I created a support site at http://forums.avirtualhome.com where you can ask que
39
  None
40
 
41
  == Arbitrary section ==
 
 
42
  * Version 1.2
43
  * When no category or an empty category is selected the dropdown menu shows Select Category, like the default category widget.
44
  * Version 1.1
1
  === Extended Categories Widget ===
2
+ Contributors: petervanderdoes, datafeedr.com
3
  Donate link: http://blog.avirtualhome.com/wordpress-plugins/
4
  Tags: extended, categories, widget
5
  Requires at least: 2.3
6
+ Tested up to: 2.6
7
+ Stable tag: 1.3
8
 
9
  Replacement of the category widget to allow for greater customization of the category widget.
10
 
18
  * Show categories hierarchical.
19
  * Sort by ID, Name,Count.
20
  * Sort ascending or descending.
21
+ * Select which categories to show. (Requires WordPress 2.5.1 or higher)
22
 
23
  == Installation ==
24
 
25
  The Extended Categories Widget can be installed in 3 easy steps:
26
 
27
+ 1. Unzip the extended-categories-widget archive and put the directory "extended-categories-widget" into your "plugins" folder (wp-content/plugins/).
28
 
29
  1. Activate the plugin
30
 
40
  None
41
 
42
  == Arbitrary section ==
43
+ * Version 1.3
44
+ * You can select which categories to show (Requires WordPress 2.5.1 or higher).
45
  * Version 1.2
46
  * When no category or an empty category is selected the dropdown menu shows Select Category, like the default category widget.
47
  * Version 1.1
widget_extended_categories.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Extended Category Widget
4
  Plugin URI: http://blog.avirtualhome.com/wordpress-plugins
5
  Description: Replacement of the category widget to allow for greater customization of the category widget.
6
- Version: 1.2
7
  Author: Peter van der Does
8
  Author URI: http://blog.avirtualhome.com/
9
 
@@ -25,137 +25,192 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
  */
26
 
27
  function widget_extended_categories_init() {
28
- // Widgets exists?
29
- if ( !function_exists('wp_register_sidebar_widget') || !function_exists('wp_register_widget_control') ) {
30
- return;
31
- }
32
-
33
- function widget_extended_categories($args) {
34
- extract($args);
35
- $options = get_option('widget_extended_categories');
36
- $c = $options['count'] ? '1' : '0';
37
- $h = $options['hierarchical'] ? '1' : '0';
38
- $e = $options['hide_empty'] ? '1' : '0';
39
- $s = $options['sort_column'] ? $options['sort_column'] : 'name';
40
- $o = $options['sort_order'] ? $options['sort_order'] : 'asc';
41
- $title = empty($options['title']) ? __('Categories') : $options['title'];
42
- $style = empty($options['style']) ? 'list' : $options['style'];
43
- $cat_args = array('orderby' => $s, 'order' => $o, 'show_count' => $c, 'hide_empty' => $e, 'hierarchical' => $h, 'title_li' => '', 'show_option_none' => __('Select Category'));
44
-
45
- echo $before_widget;
46
- echo $before_title . $title . $after_title; ?>
47
- <ul>
48
- <?php
49
- if ($style == 'list') {
50
- wp_list_categories($cat_args);
51
- } else {
52
- wp_dropdown_categories($cat_args); ?>
53
- <script lang='javascript'><!--
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  var dropdown = document.getElementById("cat");
55
  function onCatChange() {
56
  if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
57
- location.href = "<?php echo get_option('home'); ?>/?cat="+dropdown.options[dropdown.selectedIndex].value;
 
 
58
  }
59
  }
60
  dropdown.onchange = onCatChange;
61
  --></script>
62
  <?php
63
-
64
- }
65
- ?>
66
- </ul>
67
- <?php echo $after_widget; ?>
68
- <?php
69
- }
70
-
71
- function widget_extended_categories_control() {
72
- // Get actual options
73
- $options = $newoptions = get_option('widget_extended_categories');
74
- if ( !is_array($options) ) {
75
- $options = $newoptions = array ();
76
- }
77
-
78
- // Post to new options array
79
- if ( $_POST['categories-submit'] ) {
80
- $newoptions['title'] = strip_tags(stripslashes($_POST['categories-title']));
81
- $newoptions['count'] = isset($_POST['categories-count']);
82
- $newoptions['hierarchical'] = isset($_POST['categories-hierarchical']);
83
- $newoptions['hide_empty'] = isset($_POST['categories-hide_empty']);
84
- $newoptions['sort_column'] = strip_tags(stripslashes($_POST['categories-sort_column']));
85
- $newoptions['sort_order'] = strip_tags(stripslashes($_POST['categories-sort_order']));
86
- $newoptions['style'] = strip_tags(stripslashes($_POST['categories-style']));
87
- }
88
-
89
- // Update if new options
90
- if ( $options != $newoptions ) {
91
- $options = $newoptions;
92
- update_option('widget_extended_categories', $options);
93
- }
94
-
95
- // Prepare data for display
96
- $title = htmlspecialchars($options['title'], ENT_QUOTES);
97
- $count = $options['count'] ? 'checked="checked"' : '';
98
- $hierarchical = $options['hierarchical'] ? 'checked="checked"' : '';
99
- $hide_empty = $options['hide_empty'] ? 'checked="checked"' : '';
100
- $sort_id = ($options['sort_column'] == 'ID') ? ' SELECTED' : '';
101
- $sort_name = ($options['sort_column'] == 'name') ? ' SELECTED' : '';
102
- $sort_count = ($options['sort_column'] == 'count') ? ' SELECTED' : '';
103
- $sort_order_a = ($options['sort_order'] == 'asc') ? ' SELECTED' : '';
104
- $sort_order_d = ($options['sort_order'] == 'desc') ? ' SELECTED' : '';
105
- $style_list = ($options['style'] == 'list') ? ' SELECTED' : '';
106
- $style_drop = ($options['style'] == 'drop') ? ' SELECTED' : '';
107
- ?>
108
- <div>
109
- <label for="categories-title"><?php _e('Title:'); ?>
110
- <input style="width: 250px;" id="categories-title" name="categories-title" type="text" value="<?php echo $title; ?>" />
111
- </label>
112
-
113
- <label for="categories-count" style="line-height: 35px; display: block;">Show post counts
114
- <input class="checkbox" type="checkbox" <?php echo $count; ?> id="categories-count" name="categories-count" />
115
- </label>
116
-
117
- <label for="categories-hierarchical" style="line-height: 35px; display: block;">Show hierarchy
118
- <input class="checkbox" type="checkbox" <?php echo $hierarchical; ?> id="categories-hierarchical" name="categories-hierarchical" />
119
- </label>
120
-
121
- <label for="categories-hide_empty" style="line-height: 35px; display: block;">Hide empty categories
122
- <input class="checkbox" type="checkbox" <?php echo $hide_empty; ?> id="categories-hide_empty" name="categories-hide_empty" />
123
- </label>
124
-
125
- <label for="categories-sort_column" style="line-height: 35px; display: block;">Sort by
126
- <select id="categories-sort_column" name="categories-sort_column">
127
- <option value="ID" <?php echo $sort_id ?>>ID</option>
128
- <option value="name" <?php echo $sort_name ?>>Name</option>
129
- <option value="count" <?php echo $sort_count ?>>Count</option>
130
- </select>
131
- </label>
132
-
133
- <label for="categories-sort_order" style="line-height: 35px; display: block;">Sort order
134
- <select id="categories-sort_order" name="categories-sort_order">
135
- <option value="asc" <?php echo $sort_order_a ?>>Ascending</option>
136
- <option value="desc" <?php echo $sort_order_d ?>>Descending</option>
137
- </select>
138
- </label>
139
-
140
- <label for="categories-style" style="line-height: 35px; display: block;">Display style
141
- <select id="categories-style" name="categories-style">
142
- <option value='list' <?php echo $style_list; ?>>List</option>
143
- <option value='drop' <?php echo $style_drop; ?>>Drop down</option>
144
- </select>
145
- </label>
146
-
147
- <input type="hidden" id="categories-submit" name="categories-submit" value="1" />
148
- </div>
149
- <?php
150
- }
151
-
152
- function widget_extended_categories_register() {
153
- wp_register_sidebar_widget('extended-categories', 'Extended Categories', 'widget_extended_categories');
154
- wp_register_widget_control('extended-categories', 'Extended Categories', 'widget_extended_categories_control',array('width' => 300, 'height' => 245));
155
- }
156
-
157
- // Launch Widgets
158
- widget_extended_categories_register();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
  }
160
- add_action('plugins_loaded', 'widget_extended_categories_init');
161
  ?>
3
  Plugin Name: Extended Category Widget
4
  Plugin URI: http://blog.avirtualhome.com/wordpress-plugins
5
  Description: Replacement of the category widget to allow for greater customization of the category widget.
6
+ Version: 1.3
7
  Author: Peter van der Does
8
  Author URI: http://blog.avirtualhome.com/
9
 
25
  */
26
 
27
  function widget_extended_categories_init() {
28
+ // Widgets exists?
29
+ if (! function_exists ( 'wp_register_sidebar_widget' ) || ! function_exists ( 'wp_register_widget_control' )) {
30
+ return;
31
+ }
32
+
33
+ function widget_extended_categories($args) {
34
+ // Check for version
35
+ global $wp_version;
36
+ if ( version_compare($wp_version, '2.5.1', '<') ) {
37
+ $avh_extcat_canselectcats=false;
38
+ } else {
39
+ $avh_extcat_canselectcats=true;
40
+ }
41
+ extract ( $args );
42
+ $options = get_option ( 'widget_extended_categories' );
43
+ $c = $options ['count'] ? '1' : '0';
44
+ $h = $options ['hierarchical'] ? '1' : '0';
45
+ $e = $options ['hide_empty'] ? '1' : '0';
46
+ $s = $options ['sort_column'] ? $options ['sort_column'] : 'name';
47
+ $o = $options ['sort_order'] ? $options ['sort_order'] : 'asc';
48
+ $title = empty ( $options ['title'] ) ? __ ( 'Categories' ) : $options ['title'];
49
+ $style = empty ( $options ['style'] ) ? 'list' : $options ['style'];
50
+ if ($avh_extcat_canselectcats) {
51
+ if ($options ['post_category']) {
52
+ $post_category = unserialize ( $options ['post_category'] );
53
+ $included_cats = implode ( ",", $post_category );
54
+ }
55
+ $cat_args = array ('include' => $included_cats, 'orderby' => $s, 'order' => $o, 'show_count' => $c, 'hide_empty' => $e, 'hierarchical' => $h, 'title_li' => '', 'show_option_none' => __ ( 'Select Category' ) );
56
+ } else {
57
+ $cat_args = array ('orderby' => $s, 'order' => $o, 'show_count' => $c, 'hide_empty' => $e, 'hierarchical' => $h, 'title_li' => '', 'show_option_none' => __ ( 'Select Category' ) );
58
+ }
59
+ echo $before_widget;
60
+ echo '<!-- AVH Extended Categories | http://blog.avirtualhome.com/wordpress-plugins/ -->';
61
+ echo $before_title . $title . $after_title;
62
+ echo '<ul>';
63
+
64
+ if ($style == 'list') {
65
+ wp_list_categories ( $cat_args );
66
+ } else {
67
+ wp_dropdown_categories ( $cat_args );
68
+ ?>
69
+ <script lang='javascript'><!--
70
  var dropdown = document.getElementById("cat");
71
  function onCatChange() {
72
  if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
73
+ location.href = "<?php
74
+ echo get_option ( 'home' );
75
+ ?>/?cat="+dropdown.options[dropdown.selectedIndex].value;
76
  }
77
  }
78
  dropdown.onchange = onCatChange;
79
  --></script>
80
  <?php
81
+ }
82
+ echo '</ul>';
83
+ echo $after_widget;
84
+ }
85
+
86
+ function widget_extended_categories_control() {
87
+ // Check for version
88
+ global $wp_version;
89
+ if ( version_compare($wp_version, '2.5.1', '<') ) {
90
+ $avh_extcat_canselectcats=false;
91
+ } else {
92
+ $avh_extcat_canselectcats=true;
93
+ }
94
+ // Get actual options
95
+ $options = $newoptions = get_option ( 'widget_extended_categories' );
96
+ if (! is_array ( $options )) {
97
+ $options = $newoptions = array ( );
98
+ }
99
+
100
+ // Post to new options array
101
+ if ($_POST ['categories-submit']) {
102
+ $newoptions ['title'] = strip_tags ( stripslashes ( $_POST ['categories-title'] ) );
103
+ $newoptions ['count'] = isset ( $_POST ['categories-count'] );
104
+ $newoptions ['hierarchical'] = isset ( $_POST ['categories-hierarchical'] );
105
+ $newoptions ['hide_empty'] = isset ( $_POST ['categories-hide_empty'] );
106
+ $newoptions ['sort_column'] = strip_tags ( stripslashes ( $_POST ['categories-sort_column'] ) );
107
+ $newoptions ['sort_order'] = strip_tags ( stripslashes ( $_POST ['categories-sort_order'] ) );
108
+ $newoptions ['style'] = strip_tags ( stripslashes ( $_POST ['categories-style'] ) );
109
+ if ($avh_extcat_canselectcats) {
110
+ if (in_array ( '-1', $_POST ['post_category'], true )) {
111
+ $newoptions ['post_category'] = false;
112
+ } else {
113
+ $newoptions ['post_category'] = serialize ( $_POST ['post_category'] );
114
+ }
115
+ }
116
+
117
+ }
118
+
119
+ // Update if new options
120
+ if ($options != $newoptions) {
121
+ $options = $newoptions;
122
+ update_option ( 'widget_extended_categories', $options );
123
+ }
124
+
125
+ // Prepare data for display
126
+ $title = htmlspecialchars ( $options ['title'], ENT_QUOTES );
127
+ $count = $options ['count'] ? 'checked="checked"' : '';
128
+ $hierarchical = $options ['hierarchical'] ? 'checked="checked"' : '';
129
+ $hide_empty = $options ['hide_empty'] ? 'checked="checked"' : '';
130
+ $sort_id = ($options ['sort_column'] == 'ID') ? ' SELECTED' : '';
131
+ $sort_name = ($options ['sort_column'] == 'name') ? ' SELECTED' : '';
132
+ $sort_count = ($options ['sort_column'] == 'count') ? ' SELECTED' : '';
133
+ $sort_order_a = ($options ['sort_order'] == 'asc') ? ' SELECTED' : '';
134
+ $sort_order_d = ($options ['sort_order'] == 'desc') ? ' SELECTED' : '';
135
+ $style_list = ($options ['style'] == 'list') ? ' SELECTED' : '';
136
+ $style_drop = ($options ['style'] == 'drop') ? ' SELECTED' : '';
137
+ if ($avh_extcat_canselectcats) {
138
+ $selected_cats = ($options ['post_category'] != '') ? unserialize ( $options ['post_category'] ) : false;
139
+ }
140
+ ?>
141
+ <div>
142
+ <label for="categories-title"><?php _e ( 'Title:' ); ?>
143
+ <input style="width: 250px;" id="categories-title" name="categories-title" type="text" value="<?php echo $title; ?>" />
144
+ </label>
145
+ <label for="categories-count" style="line-height: 35px; display: block;">Show post counts <input class="checkbox" type="checkbox" <?php echo $count;
146
+ ?>
147
+ id="categories-count" name="categories-count" /> </label> <label
148
+ for="categories-hierarchical"
149
+ style="line-height: 35px; display: block;">Show hierarchy <input
150
+ class="checkbox" type="checkbox" <?php
151
+ echo $hierarchical;
152
+ ?>
153
+ id="categories-hierarchical" name="categories-hierarchical" /> </label>
154
+
155
+ <label for="categories-hide_empty"
156
+ style="line-height: 35px; display: block;">Hide empty categories <input
157
+ class="checkbox" type="checkbox" <?php
158
+ echo $hide_empty;
159
+ ?>
160
+ id="categories-hide_empty" name="categories-hide_empty" /> </label> <label
161
+ for="categories-sort_column" style="line-height: 35px; display: block;">Sort
162
+ by <select id="categories-sort_column" name="categories-sort_column">
163
+ <option value="ID" <?php
164
+ echo $sort_id?>>ID</option>
165
+ <option value="name" <?php
166
+ echo $sort_name?>>Name</option>
167
+ <option value="count" <?php
168
+ echo $sort_count?>>Count</option>
169
+ </select> </label> <label for="categories-sort_order"
170
+ style="line-height: 35px; display: block;">Sort order <select
171
+ id="categories-sort_order" name="categories-sort_order">
172
+ <option value="asc" <?php
173
+ echo $sort_order_a?>>Ascending</option>
174
+ <option value="desc" <?php
175
+ echo $sort_order_d?>>Descending</option>
176
+ </select> </label> <label for="categories-style"
177
+ style="line-height: 35px; display: block;">Display style <select
178
+ id="categories-style" name="categories-style">
179
+ <option value='list' <?php
180
+ echo $style_list;
181
+ ?>>List</option>
182
+ <option value='drop' <?php
183
+ echo $style_drop;
184
+ ?>>Drop down</option>
185
+ </select> </label>
186
+ <?php
187
+ if ($avh_extcat_canselectcats) {
188
+ echo ' <b>Include these categories</b><hr />';
189
+ echo ' <ul id="categorychecklist" class="list:category categorychecklist form-no-clear" style="list-style-type: none; margin-left: 5px; padding-left: 0px; margin-bottom: 20px;">';
190
+ echo ' <li id="category--1" class="popular-category">';
191
+ echo ' <label for="in-category--1" class="selectit">';
192
+ echo ' <input value="-1" name="post_category[]" id="in-category--1" type="checkbox"';
193
+ if (!$selected_cats) { echo 'checked'; }
194
+ echo '> Include All Categories';
195
+ echo ' </label>';
196
+ echo ' </li>';
197
+ wp_category_checklist(0,0,$selected_cats);
198
+ echo ' </ul>';
199
+ }
200
+ ?>
201
+
202
+ <input type="hidden" id="categories-submit" name="categories-submit"
203
+ value="1" /></div>
204
+ <?php
205
+ }
206
+
207
+ function widget_extended_categories_register() {
208
+ wp_register_sidebar_widget ( 'extended-categories', 'Extended Categories', 'widget_extended_categories' );
209
+ wp_register_widget_control ( 'extended-categories', 'Extended Categories', 'widget_extended_categories_control', array ('width' => 300, 'height' => 245 ) );
210
+ }
211
+
212
+ // Launch Widgets
213
+ widget_extended_categories_register ();
214
  }
215
+ add_action ( 'plugins_loaded', 'widget_extended_categories_init' );
216
  ?>