Category Posts Widget - Version 3.2

Version Description

Note that version 3.0 drops support for Simple Post Thumbnails plugin in favor of WP 2.9's built in post thumbnail functionality.

Download this release

Release Info

Developer ZephyrWest
Plugin Icon 128x128 Category Posts Widget
Version 3.2
Comparing to
See all releases

Code changes from version 3.1 to 3.2

Files changed (3) hide show
  1. cat-posts.php +42 -5
  2. readme.txt +7 -3
  3. screenshot-1.png +0 -0
cat-posts.php CHANGED
@@ -1,10 +1,10 @@
1
  <?php
2
  /*
3
  Plugin Name: Category Posts Widget
4
- Plugin URI: http://jameslao.com/2009/12/30/category-posts-widget-3-0/
5
  Description: Adds a widget that can display posts from a single category.
6
  Author: James Lao
7
- Version: 3.1
8
  Author URI: http://jameslao.com/
9
  */
10
 
@@ -40,10 +40,25 @@ function widget($args, $instance) {
40
  if( !$instance["title"] ) {
41
  $category_info = get_category($instance["cat"]);
42
  $instance["title"] = $category_info->name;
43
- }
 
 
 
 
 
 
 
 
 
 
44
 
45
  // Get array of post info.
46
- $cat_posts = new WP_Query("showposts=" . $instance["num"] . "&cat=" . $instance["cat"]);
 
 
 
 
 
47
 
48
  // Excerpt length filter
49
  $new_excerpt_length = create_function('$length', "return " . $instance["excerpt_length"] . ";");
@@ -156,8 +171,30 @@ function form($instance) {
156
  <?php _e('Number of posts to show'); ?>:
157
  <input style="text-align: center;" id="<?php echo $this->get_field_id("num"); ?>" name="<?php echo $this->get_field_name("num"); ?>" type="text" value="<?php echo absint($instance["num"]); ?>" size='3' />
158
  </label>
159
- </p>
 
 
 
 
 
 
 
 
 
 
 
 
160
 
 
 
 
 
 
 
 
 
 
 
161
  <p>
162
  <label for="<?php echo $this->get_field_id("title_link"); ?>">
163
  <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("title_link"); ?>" name="<?php echo $this->get_field_name("title_link"); ?>"<?php checked( (bool) $instance["title_link"], true ); ?> />
1
  <?php
2
  /*
3
  Plugin Name: Category Posts Widget
4
+ Plugin URI: http://jameslao.com/2011/03/24/category-posts-widget-3-2/
5
  Description: Adds a widget that can display posts from a single category.
6
  Author: James Lao
7
+ Version: 3.2
8
  Author URI: http://jameslao.com/
9
  */
10
 
40
  if( !$instance["title"] ) {
41
  $category_info = get_category($instance["cat"]);
42
  $instance["title"] = $category_info->name;
43
+ }
44
+
45
+ $valid_sort_orders = array('date', 'title', 'comment_count', 'random');
46
+ if ( in_array($instance['sort_by'], $valid_sort_orders) ) {
47
+ $sort_by = $instance['sort_by'];
48
+ $sort_order = (bool) $instance['asc_sort_order'] ? 'ASC' : 'DESC';
49
+ } else {
50
+ // by default, display latest first
51
+ $sort_by = 'date';
52
+ $sort_order = 'DESC';
53
+ }
54
 
55
  // Get array of post info.
56
+ $cat_posts = new WP_Query(
57
+ "showposts=" . $instance["num"] .
58
+ "&cat=" . $instance["cat"] .
59
+ "&orderby=" . $sort_by .
60
+ "&order=" . $sort_order
61
+ );
62
 
63
  // Excerpt length filter
64
  $new_excerpt_length = create_function('$length', "return " . $instance["excerpt_length"] . ";");
171
  <?php _e('Number of posts to show'); ?>:
172
  <input style="text-align: center;" id="<?php echo $this->get_field_id("num"); ?>" name="<?php echo $this->get_field_name("num"); ?>" type="text" value="<?php echo absint($instance["num"]); ?>" size='3' />
173
  </label>
174
+ </p>
175
+
176
+ <p>
177
+ <label for="<?php echo $this->get_field_id("sort_by"); ?>">
178
+ <?php _e('Sort by'); ?>:
179
+ <select id="<?php echo $this->get_field_id("sort_by"); ?>" name="<?php echo $this->get_field_name("sort_by"); ?>">
180
+ <option value="date"<?php selected( $instance["sort_by"], "date" ); ?>>Date</option>
181
+ <option value="title"<?php selected( $instance["sort_by"], "title" ); ?>>Title</option>
182
+ <option value="comment_count"<?php selected( $instance["sort_by"], "comment_count" ); ?>>Number of comments</option>
183
+ <option value="random"<?php selected( $instance["sort_by"], "random" ); ?>>Random</option>
184
+ </select>
185
+ </label>
186
+ </p>
187
 
188
+ <p>
189
+ <label for="<?php echo $this->get_field_id("asc_sort_order"); ?>">
190
+ <input type="checkbox" class="checkbox"
191
+ id="<?php echo $this->get_field_id("asc_sort_order"); ?>"
192
+ name="<?php echo $this->get_field_name("asc_sort_order"); ?>"
193
+ <?php checked( (bool) $instance["asc_sort_order"], true ); ?> />
194
+ <?php _e( 'Reverse sort order (ascending)' ); ?>
195
+ </label>
196
+ </p>
197
+
198
  <p>
199
  <label for="<?php echo $this->get_field_id("title_link"); ?>">
200
  <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("title_link"); ?>" name="<?php echo $this->get_field_name("title_link"); ?>"<?php checked( (bool) $instance["title_link"], true ); ?> />
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: James Lao
3
  Donate link: http://jameslao.com/
4
  Tags: category, posts, widget
5
  Requires at least: 2.8
6
- Tested up to: 2.9
7
- Stable tag: 3.1
8
 
9
  Adds a widget that shows the most recent posts in a single category.
10
 
@@ -14,6 +14,7 @@ Category Posts Widget is a light widget designed to do one thing and do it well:
14
 
15
  Features:
16
 
 
17
  * Support for displaying thumbnail images via WP 2.9's new post thumbnail feature.
18
  * Set how many posts to show.
19
  * Set which category the posts should come form.
@@ -40,6 +41,9 @@ Note that version 3.0 drops support for [Simple Post Thumbnails plugin](http://w
40
 
41
  == Changelog ==
42
 
 
 
 
43
  3.1
44
 
45
  * Fixed a bug in the thumbnail size registration routine.
@@ -63,4 +67,4 @@ Note that version 3.0 drops support for [Simple Post Thumbnails plugin](http://w
63
  2.0
64
 
65
  * Updated to use the WP 2.8 widget API.
66
- * Added support for [Simple Post Thumbnails plugin](http://wordpress.org/extend/plugins/simple-post-thumbnails/).
3
  Donate link: http://jameslao.com/
4
  Tags: category, posts, widget
5
  Requires at least: 2.8
6
+ Tested up to: 3.1
7
+ Stable tag: 3.2
8
 
9
  Adds a widget that shows the most recent posts in a single category.
10
 
14
 
15
  Features:
16
 
17
+ * [NEW] Option to change ordering of posts.
18
  * Support for displaying thumbnail images via WP 2.9's new post thumbnail feature.
19
  * Set how many posts to show.
20
  * Set which category the posts should come form.
41
 
42
  == Changelog ==
43
 
44
+ 3.2
45
+ * Added option to change ordering of posts. Defaults to showing newest posts first.
46
+
47
  3.1
48
 
49
  * Fixed a bug in the thumbnail size registration routine.
67
  2.0
68
 
69
  * Updated to use the WP 2.8 widget API.
70
+ * Added support for [Simple Post Thumbnails plugin](http://wordpress.org/extend/plugins/simple-post-thumbnails/).
screenshot-1.png CHANGED
Binary file