Category Posts Widget - Version 4.1.3

Version Description

  • Please consider to re-configure the widget as the latest version has numerous changes from previous.
  • Version 4.0 uses CSS file for styling the widget in front end.
  • Version 3.0 or later version uses WordPress 2.9's built in post thumbnail functionality.
Download this release

Release Info

Developer Kometschuh
Plugin Icon 128x128 Category Posts Widget
Version 4.1.3
Comparing to
See all releases

Code changes from version 4.1.2 to 4.1.3

Files changed (3) hide show
  1. cat-posts.css +41 -41
  2. cat-posts.php +364 -352
  3. readme.txt +21 -11
cat-posts.css CHANGED
@@ -1,41 +1,41 @@
1
- /*
2
- Default CSS Styles for the Category Posts Widget plugin
3
- Version: 4.1.2
4
- */
5
- .cat-post-current,
6
- .cat-post-date,
7
- .cat-post-comment-num {
8
- font-size: 12px;
9
- line-height: 18px;
10
- }
11
- .cat-post-title {
12
- font-size: 15px;
13
- }
14
- .cat-post-current a {
15
- font-weight: bold;
16
- text-transform: uppercase;
17
- }
18
- .cat-post-date {
19
- font-style: italic;
20
- margin-bottom: 0;
21
- }
22
- .cat-post-thumbnail img {
23
- float: left;
24
- margin: 5px 10px 5px 0;
25
- }
26
- .cat-post-item {
27
- border-bottom: 1px solid #ccc;
28
- list-style: none;
29
- list-style-type: none;
30
- margin: 3px 0;
31
- padding: 3px 0;
32
- }
33
- .cat-post-item:before,
34
- .cat-post-item:after {
35
- content: "";
36
- display: table;
37
- clear: both;
38
- }
39
- .cat-post-item:last-child {
40
- border-bottom: none;
41
- }
1
+ /*
2
+ Default CSS Styles for the Category Posts Widget plugin
3
+ Version: 4.1.3
4
+ */
5
+ .cat-post-current,
6
+ .cat-post-date,
7
+ .cat-post-comment-num {
8
+ font-size: 12px;
9
+ line-height: 18px;
10
+ }
11
+ .cat-post-title {
12
+ font-size: 15px;
13
+ }
14
+ .cat-post-current a {
15
+ font-weight: bold;
16
+ text-transform: uppercase;
17
+ }
18
+ .cat-post-date {
19
+ font-style: italic;
20
+ margin-bottom: 0;
21
+ }
22
+ .cat-post-thumbnail img {
23
+ float: left;
24
+ margin: 5px 10px 5px 0;
25
+ }
26
+ .cat-post-item {
27
+ border-bottom: 1px solid #ccc;
28
+ list-style: none;
29
+ list-style-type: none;
30
+ margin: 3px 0;
31
+ padding: 3px 0;
32
+ }
33
+ .cat-post-item:before,
34
+ .cat-post-item:after {
35
+ content: "";
36
+ display: table;
37
+ clear: both;
38
+ }
39
+ .cat-post-item:last-child {
40
+ border-bottom: none;
41
+ }
cat-posts.php CHANGED
@@ -1,352 +1,364 @@
1
- <?php
2
- /*
3
- Plugin Name: Category Posts Widget
4
- Plugin URI: http://mkrdip.me/category-posts-widget
5
- Description: Adds a widget that shows the most recent posts from a single category.
6
- Author: Mrinal Kanti Roy
7
- Version: 4.1.2
8
- Author URI: http://mkrdip.me
9
- */
10
-
11
- // Don't call the file directly
12
- if ( !defined( 'ABSPATH' ) ) exit;
13
-
14
- /**
15
- * Register our styles
16
- *
17
- * @return void
18
- */
19
- add_action( 'wp_enqueue_scripts', 'category_posts_widget_styles' );
20
-
21
- function category_posts_widget_styles() {
22
- wp_register_style( 'category-posts', plugins_url( 'category-posts/cat-posts.css' ) );
23
- wp_enqueue_style( 'category-posts' );
24
- }
25
-
26
- /**
27
- * Register thumbnail sizes.
28
- *
29
- * @return void
30
- */
31
- function category_posts_add_image_size(){
32
- $sizes = get_option('mkrdip_cat_post_thumb_sizes');
33
-
34
- if ( $sizes ){
35
- foreach ( $sizes as $id=>$size ) {
36
- add_image_size( 'cat_post_thumb_size' . $id, $size[0], $size[1], true );
37
- }
38
- }
39
- }
40
-
41
- add_action( 'init', 'category_posts_add_image_size' );
42
-
43
-
44
- /**
45
- * Category Posts Widget Class
46
- *
47
- * Shows the single category posts with some configurable options
48
- */
49
- class CategoryPosts extends WP_Widget {
50
-
51
- function __construct() {
52
- $widget_ops = array('classname' => 'cat-post-widget', 'description' => __('List single category posts'));
53
- parent::__construct('category-posts', __('Category Posts'), $widget_ops);
54
- }
55
-
56
- // Displays category posts widget on blog.
57
- function widget($args, $instance) {
58
- global $post;
59
- $post_old = $post; // Save the post object.
60
-
61
- extract( $args );
62
-
63
- $sizes = get_option('mkrdip_cat_post_thumb_sizes');
64
-
65
- // If not title, use the name of the category.
66
- if( !$instance["title"] ) {
67
- $category_info = get_category($instance["cat"]);
68
- $instance["title"] = $category_info->name;
69
- }
70
-
71
- $valid_sort_orders = array('date', 'title', 'comment_count', 'rand');
72
- if ( in_array($instance['sort_by'], $valid_sort_orders) ) {
73
- $sort_by = $instance['sort_by'];
74
- $sort_order = (bool) isset( $instance['asc_sort_order'] ) ? 'ASC' : 'DESC';
75
- } else {
76
- // by default, display latest first
77
- $sort_by = 'date';
78
- $sort_order = 'DESC';
79
- }
80
-
81
- // Get array of post info.
82
- $cat_posts = new WP_Query(
83
- "showposts=" . $instance["num"] .
84
- "&cat=" . $instance["cat"] .
85
- "&orderby=" . $sort_by .
86
- "&order=" . $sort_order
87
- );
88
-
89
- // Excerpt length filter
90
- $new_excerpt_length = create_function('$length', "return " . $instance["excerpt_length"] . ";");
91
- if ( $instance["excerpt_length"] > 0 )
92
- add_filter('excerpt_length', $new_excerpt_length);
93
-
94
- echo $before_widget;
95
-
96
- // Widget title
97
- if( !isset ( $instance["hide_title"] ) ) {
98
- echo $before_title;
99
- if( isset ( $instance["title_link"] ) ) {
100
- echo '<a href="' . get_category_link($instance["cat"]) . '">' . $instance["title"] . '</a>';
101
- } else {
102
- echo $instance["title"];
103
- }
104
- echo $after_title;
105
- }
106
-
107
- // Post list
108
- echo "<ul>\n";
109
-
110
- while ( $cat_posts->have_posts() )
111
- {
112
- $cat_posts->the_post(); ?>
113
-
114
- <li <?php if( !isset( $instance['disable_css'] ) ) {
115
- echo "class=\"cat-post-item";
116
- if ( is_single(get_the_title() ) ) { echo " cat-post-current"; }
117
- echo "\"";
118
- } ?> >
119
-
120
- <?php
121
- if( isset( $instance["thumbTop"] ) ) :
122
- if ( function_exists('the_post_thumbnail') &&
123
- current_theme_supports("post-thumbnails") &&
124
- isset( $instance["thumb"] ) &&
125
- has_post_thumbnail() ) : ?>
126
- <a <?php if( !isset( $instance['disable_css'] ) ) { echo "class=\"cat-post-thumbnail\""; } ?>
127
- href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
128
- <?php the_post_thumbnail( 'cat_post_thumb_size'.$this->id ); ?>
129
- </a>
130
- <?php endif;
131
- endif; ?>
132
-
133
- <a class="post-title <?php if( !isset( $instance['disable_css'] ) ) { echo " cat-post-title"; } ?>"
134
- href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?>
135
- </a>
136
-
137
- <?php if ( isset( $instance['date'] ) ) : ?>
138
- <p class="post-date <?php if( !isset( $instance['disable_css'] ) ) { echo " cat-post-date"; } ?>">
139
- <?php the_time("j M Y"); ?>
140
- </p>
141
- <?php endif;
142
-
143
- if( !isset( $instance["thumbTop"] ) ) :
144
- if ( function_exists('the_post_thumbnail') &&
145
- current_theme_supports("post-thumbnails") &&
146
- isset( $instance["thumb"] ) &&
147
- has_post_thumbnail() ) : ?>
148
- <a <?php if( !isset( $instance['disable_css'] ) ) { echo "class=\"cat-post-thumbnail\""; } ?>
149
- href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
150
- <?php the_post_thumbnail( 'cat_post_thumb_size'.$this->id ); ?>
151
- </a>
152
- <?php endif;
153
- endif;
154
-
155
- if ( isset( $instance['excerpt'] ) ) :
156
- the_excerpt();
157
- endif;
158
-
159
- if ( isset( $instance['comment_num'] ) ) : ?>
160
- <p class="comment-num <?php if( !isset( $instance['disable_css'] ) ) { echo "cat-post-comment-num"; } ?>">
161
- (<?php comments_number(); ?>)
162
- </p>
163
- <?php endif; ?>
164
- </li>
165
- <?php
166
- }
167
-
168
- echo "</ul>\n";
169
-
170
- echo $after_widget;
171
-
172
- remove_filter('excerpt_length', $new_excerpt_length);
173
-
174
- if (function_exists ('wp_reset_postdata')) //wp_reset_postdata only exists in WordPress >3.0.0
175
- wp_reset_postdata();
176
- }
177
-
178
- /**
179
- * Update the options
180
- *
181
- * @param array $new_instance
182
- * @param array $old_instance
183
- * @return array
184
- */
185
- function update($new_instance, $old_instance) {
186
-
187
- // thumbnail size
188
- $sizes = get_option('mkrdip_cat_post_thumb_sizes');
189
- if ( !$sizes ) {
190
- $sizes = array();
191
- }
192
- $sizes[$this->id] = array($new_instance['thumb_w'], $new_instance['thumb_h']);
193
- update_option('mkrdip_cat_post_thumb_sizes', $sizes);
194
-
195
- return $new_instance;
196
- }
197
-
198
- /**
199
- * The widget configuration form back end.
200
- *
201
- * @param array $instance
202
- * @return void
203
- */
204
- function form($instance) {
205
- $instance = wp_parse_args( ( array ) $instance, array(
206
- 'title' => __( '' ),
207
- 'hide_title' => __( '' ),
208
- 'cat' => __( '' ),
209
- 'num' => __( '' ),
210
- 'sort_by' => __( '' ),
211
- 'asc_sort_order' => __( '' ),
212
- 'title_link' => __( '' ),
213
- 'excerpt' => __( '' ),
214
- 'excerpt_length' => __( '' ),
215
- 'comment_num' => __( '' ),
216
- 'date' => __( '' ),
217
- 'thumb' => __( '' ),
218
- 'thumbTop' => __( '' ),
219
- 'thumb_w' => __( '' ),
220
- 'thumb_h' => __( '' ),
221
- 'disable_css' => __( '' )
222
- ) );
223
-
224
- $title = $instance['title'];
225
- $hide_title = $instance['hide_title'];
226
- $cat = $instance['cat'];
227
- $num = $instance['num'];
228
- $sort_by = $instance['sort_by'];
229
- $asc_sort_order = $instance['asc_sort_order'];
230
- $title_link = $instance['title_link'];
231
- $excerpt = $instance['excerpt'];
232
- $excerpt_length = $instance['excerpt_length'];
233
- $comment_num = $instance['comment_num'];
234
- $date = $instance['date'];
235
- $thumb = $instance['thumb'];
236
- $thumbTop = $instance['thumbTop'];
237
- $thumb_w = $instance['thumb_w'];
238
- $thumb_h = $instance['thumb_h'];
239
- $disable_css = $instance['disable_css'];
240
-
241
- ?>
242
- <p>
243
- <label for="<?php echo $this->get_field_id("title"); ?>">
244
- <?php _e( 'Title' ); ?>:
245
- <input class="widefat" id="<?php echo $this->get_field_id("title"); ?>" name="<?php echo $this->get_field_name("title"); ?>" type="text" value="<?php echo esc_attr($instance["title"]); ?>" />
246
- </label>
247
- </p>
248
- <p>
249
- <label for="<?php echo $this->get_field_id("hide_title"); ?>">
250
- <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("hide_title"); ?>" name="<?php echo $this->get_field_name("hide_title"); ?>"<?php checked( (bool) $instance["hide_title"], true ); ?> />
251
- <?php _e( 'Hide title' ); ?>
252
- </label>
253
- </p>
254
- <p>
255
- <label>
256
- <?php _e( 'Category' ); ?>:
257
- <?php wp_dropdown_categories( array( 'name' => $this->get_field_name("cat"), 'selected' => $instance["cat"] ) ); ?>
258
- </label>
259
- </p>
260
- <p>
261
- <label for="<?php echo $this->get_field_id("num"); ?>">
262
- <?php _e('Number of posts to show'); ?>:
263
- <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' />
264
- </label>
265
- </p>
266
- <p>
267
- <label for="<?php echo $this->get_field_id("sort_by"); ?>">
268
- <?php _e('Sort by'); ?>:
269
- <select id="<?php echo $this->get_field_id("sort_by"); ?>" name="<?php echo $this->get_field_name("sort_by"); ?>">
270
- <option value="date"<?php selected( $instance["sort_by"], "date" ); ?>>Date</option>
271
- <option value="title"<?php selected( $instance["sort_by"], "title" ); ?>>Title</option>
272
- <option value="comment_count"<?php selected( $instance["sort_by"], "comment_count" ); ?>>Number of comments</option>
273
- <option value="rand"<?php selected( $instance["sort_by"], "rand" ); ?>>Random</option>
274
- </select>
275
- </label>
276
- </p>
277
- <p>
278
- <label for="<?php echo $this->get_field_id("asc_sort_order"); ?>">
279
- <input type="checkbox" class="checkbox"
280
- id="<?php echo $this->get_field_id("asc_sort_order"); ?>"
281
- name="<?php echo $this->get_field_name("asc_sort_order"); ?>"
282
- <?php checked( (bool) $instance["asc_sort_order"], true ); ?> />
283
- <?php _e( 'Reverse sort order (ascending)' ); ?>
284
- </label>
285
- </p>
286
- <p>
287
- <label for="<?php echo $this->get_field_id("title_link"); ?>">
288
- <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 ); ?> />
289
- <?php _e( 'Make widget title link' ); ?>
290
- </label>
291
- </p>
292
- <p>
293
- <label for="<?php echo $this->get_field_id("excerpt"); ?>">
294
- <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("excerpt"); ?>" name="<?php echo $this->get_field_name("excerpt"); ?>"<?php checked( (bool) $instance["excerpt"], true ); ?> />
295
- <?php _e( 'Show post excerpt' ); ?>
296
- </label>
297
- </p>
298
- <p>
299
- <label for="<?php echo $this->get_field_id("excerpt_length"); ?>">
300
- <?php _e( 'Excerpt length (in words):' ); ?>
301
- </label>
302
- <input style="text-align: center;" type="text" id="<?php echo $this->get_field_id("excerpt_length"); ?>" name="<?php echo $this->get_field_name("excerpt_length"); ?>" value="<?php echo $instance["excerpt_length"]; ?>" size="3" />
303
- </p>
304
- <p>
305
- <label for="<?php echo $this->get_field_id("comment_num"); ?>">
306
- <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("comment_num"); ?>" name="<?php echo $this->get_field_name("comment_num"); ?>"<?php checked( (bool) $instance["comment_num"], true ); ?> />
307
- <?php _e( 'Show number of comments' ); ?>
308
- </label>
309
- </p>
310
- <p>
311
- <label for="<?php echo $this->get_field_id("date"); ?>">
312
- <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("date"); ?>" name="<?php echo $this->get_field_name("date"); ?>"<?php checked( (bool) $instance["date"], true ); ?> />
313
- <?php _e( 'Show post date' ); ?>
314
- </label>
315
- </p>
316
- <?php if ( function_exists('the_post_thumbnail') && current_theme_supports("post-thumbnails") ) : ?>
317
- <p>
318
- <label for="<?php echo $this->get_field_id("thumb"); ?>">
319
- <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("thumb"); ?>" name="<?php echo $this->get_field_name("thumb"); ?>"<?php checked( (bool) $instance["thumb"], true ); ?> />
320
- <?php _e( 'Show post thumbnail' ); ?>
321
- </label>
322
- </p>
323
- <p>
324
- <label for="<?php echo $this->get_field_id("thumbTop"); ?>">
325
- <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("thumbTop"); ?>" name="<?php echo $this->get_field_name("thumbTop"); ?>"<?php checked( (bool) $instance["thumbTop"], true ); ?> />
326
- <?php _e( 'Thumbnail to top' ); ?>
327
- </label>
328
- </p>
329
- <p>
330
- <label>
331
- <?php _e('Thumbnail dimensions (in pixels)'); ?>:<br />
332
- <label for="<?php echo $this->get_field_id("thumb_w"); ?>">
333
- Width: <input class="widefat" style="width:30%;" type="text" id="<?php echo $this->get_field_id("thumb_w"); ?>" name="<?php echo $this->get_field_name("thumb_w"); ?>" value="<?php echo $instance["thumb_w"]; ?>" />
334
- </label>
335
-
336
- <label for="<?php echo $this->get_field_id("thumb_h"); ?>">
337
- Height: <input class="widefat" style="width:30%;" type="text" id="<?php echo $this->get_field_id("thumb_h"); ?>" name="<?php echo $this->get_field_name("thumb_h"); ?>" value="<?php echo $instance["thumb_h"]; ?>" />
338
- </label>
339
- </label>
340
- </p>
341
- <?php endif; ?>
342
- <p>
343
- <label for="<?php echo $this->get_field_id("disable_css"); ?>">
344
- <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("disable_css"); ?>" name="<?php echo $this->get_field_name("disable_css"); ?>"<?php checked( (bool) $instance["disable_css"], true ); ?> />
345
- <?php _e( 'Disable widget CSS' ); ?>
346
- </label>
347
- </p>
348
- <?php
349
- }
350
- }
351
-
352
- add_action( 'widgets_init', create_function('', 'return register_widget("CategoryPosts");') );
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Category Posts Widget
4
+ Plugin URI: http://mkrdip.me/category-posts-widget
5
+ Description: Adds a widget that shows the most recent posts from a single category.
6
+ Author: Mrinal Kanti Roy
7
+ Version: 4.1.3
8
+ Author URI: http://mkrdip.me
9
+ */
10
+
11
+ // Don't call the file directly
12
+ if ( !defined( 'ABSPATH' ) ) exit;
13
+
14
+ /**
15
+ * Register our styles
16
+ *
17
+ * @return void
18
+ */
19
+ add_action( 'wp_enqueue_scripts', 'category_posts_widget_styles' );
20
+
21
+ function category_posts_widget_styles() {
22
+ wp_register_style( 'category-posts', plugins_url( 'category-posts/cat-posts.css' ) );
23
+ wp_enqueue_style( 'category-posts' );
24
+ }
25
+
26
+ /**
27
+ * Register thumbnail sizes.
28
+ *
29
+ * @return void
30
+ */
31
+ function category_posts_add_image_size(){
32
+ $sizes = get_option('mkrdip_cat_post_thumb_sizes');
33
+
34
+ if ( $sizes ){
35
+ foreach ( $sizes as $id=>$size ) {
36
+ add_image_size( 'cat_post_thumb_size' . $id, $size[0], $size[1], true );
37
+ }
38
+ }
39
+ }
40
+
41
+ add_action( 'init', 'category_posts_add_image_size' );
42
+
43
+
44
+ /**
45
+ * Category Posts Widget Class
46
+ *
47
+ * Shows the single category posts with some configurable options
48
+ */
49
+ class CategoryPosts extends WP_Widget {
50
+
51
+ function __construct() {
52
+ $widget_ops = array('classname' => 'cat-post-widget', 'description' => __('List single category posts'));
53
+ parent::__construct('category-posts', __('Category Posts'), $widget_ops);
54
+ }
55
+
56
+ // Displays category posts widget on blog.
57
+ function widget($args, $instance) {
58
+ global $post;
59
+ $post_old = $post; // Save the post object.
60
+
61
+ extract( $args );
62
+
63
+ $sizes = get_option('mkrdip_cat_post_thumb_sizes');
64
+
65
+ // If not title, use the name of the category.
66
+ if( !$instance["title"] ) {
67
+ $category_info = get_category($instance["cat"]);
68
+ $instance["title"] = $category_info->name;
69
+ }
70
+
71
+ $valid_sort_orders = array('date', 'title', 'comment_count', 'rand');
72
+ if ( in_array($instance['sort_by'], $valid_sort_orders) ) {
73
+ $sort_by = $instance['sort_by'];
74
+ $sort_order = (bool) isset( $instance['asc_sort_order'] ) ? 'ASC' : 'DESC';
75
+ } else {
76
+ // by default, display latest first
77
+ $sort_by = 'date';
78
+ $sort_order = 'DESC';
79
+ }
80
+
81
+ // Get array of post info.
82
+ $cat_posts = new WP_Query(
83
+ "showposts=" . $instance["num"] .
84
+ "&cat=" . $instance["cat"] .
85
+ "&orderby=" . $sort_by .
86
+ "&order=" . $sort_order
87
+ );
88
+
89
+ if ( !isset ( $instance["hide_if_empty"] ) || $cat_posts->have_posts() ) {
90
+
91
+ // Excerpt length filter
92
+ $new_excerpt_length = create_function('$length', "return " . $instance["excerpt_length"] . ";");
93
+ if ( $instance["excerpt_length"] > 0 )
94
+ add_filter('excerpt_length', $new_excerpt_length);
95
+
96
+ echo $before_widget;
97
+
98
+ // Widget title
99
+ if( !isset ( $instance["hide_title"] ) ) {
100
+ echo $before_title;
101
+ if( isset ( $instance["title_link"] ) ) {
102
+ echo '<a href="' . get_category_link($instance["cat"]) . '">' . $instance["title"] . '</a>';
103
+ } else {
104
+ echo $instance["title"];
105
+ }
106
+ echo $after_title;
107
+ }
108
+
109
+ // Post list
110
+ echo "<ul>\n";
111
+
112
+ while ( $cat_posts->have_posts() )
113
+ {
114
+ $cat_posts->the_post(); ?>
115
+
116
+ <li <?php if( !isset( $instance['disable_css'] ) ) {
117
+ echo "class=\"cat-post-item";
118
+ if ( is_single(get_the_title() ) ) { echo " cat-post-current"; }
119
+ echo "\"";
120
+ } ?> >
121
+
122
+ <?php
123
+ if( isset( $instance["thumbTop"] ) ) :
124
+ if ( function_exists('the_post_thumbnail') &&
125
+ current_theme_supports("post-thumbnails") &&
126
+ isset( $instance["thumb"] ) &&
127
+ has_post_thumbnail() ) : ?>
128
+ <a <?php if( !isset( $instance['disable_css'] ) ) { echo "class=\"cat-post-thumbnail\""; } ?>
129
+ href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
130
+ <?php the_post_thumbnail( 'cat_post_thumb_size'.$this->id ); ?>
131
+ </a>
132
+ <?php endif;
133
+ endif; ?>
134
+
135
+ <a class="post-title <?php if( !isset( $instance['disable_css'] ) ) { echo " cat-post-title"; } ?>"
136
+ href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?>
137
+ </a>
138
+
139
+ <?php if ( isset( $instance['date'] ) ) : ?>
140
+ <p class="post-date <?php if( !isset( $instance['disable_css'] ) ) { echo " cat-post-date"; } ?>">
141
+ <?php the_time("j M Y"); ?>
142
+ </p>
143
+ <?php endif;
144
+
145
+ if( !isset( $instance["thumbTop"] ) ) :
146
+ if ( function_exists('the_post_thumbnail') &&
147
+ current_theme_supports("post-thumbnails") &&
148
+ isset( $instance["thumb"] ) &&
149
+ has_post_thumbnail() ) : ?>
150
+ <a <?php if( !isset( $instance['disable_css'] ) ) { echo "class=\"cat-post-thumbnail\""; } ?>
151
+ href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
152
+ <?php the_post_thumbnail( 'cat_post_thumb_size'.$this->id ); ?>
153
+ </a>
154
+ <?php endif;
155
+ endif;
156
+
157
+ if ( isset( $instance['excerpt'] ) ) :
158
+ the_excerpt();
159
+ endif;
160
+
161
+ if ( isset( $instance['comment_num'] ) ) : ?>
162
+ <p class="comment-num <?php if( !isset( $instance['disable_css'] ) ) { echo "cat-post-comment-num"; } ?>">
163
+ (<?php comments_number(); ?>)
164
+ </p>
165
+ <?php endif; ?>
166
+ </li>
167
+ <?php
168
+ }
169
+
170
+ echo "</ul>\n";
171
+
172
+ echo $after_widget;
173
+
174
+ remove_filter('excerpt_length', $new_excerpt_length);
175
+
176
+ if (function_exists ('wp_reset_postdata')) //wp_reset_postdata only exists in WordPress >3.0.0
177
+ wp_reset_postdata();
178
+
179
+ } // END if !isset ( $instance["hide_if_empty"] ) || $cat_posts->have_posts()
180
+ }
181
+
182
+ /**
183
+ * Update the options
184
+ *
185
+ * @param array $new_instance
186
+ * @param array $old_instance
187
+ * @return array
188
+ */
189
+ function update($new_instance, $old_instance) {
190
+
191
+ // thumbnail size
192
+ $sizes = get_option('mkrdip_cat_post_thumb_sizes');
193
+ if ( !$sizes ) {
194
+ $sizes = array();
195
+ }
196
+ $sizes[$this->id] = array($new_instance['thumb_w'], $new_instance['thumb_h']);
197
+ update_option('mkrdip_cat_post_thumb_sizes', $sizes);
198
+
199
+ return $new_instance;
200
+ }
201
+
202
+ /**
203
+ * The widget configuration form back end.
204
+ *
205
+ * @param array $instance
206
+ * @return void
207
+ */
208
+ function form($instance) {
209
+ $instance = wp_parse_args( ( array ) $instance, array(
210
+ 'title' => __( '' ),
211
+ 'hide_title' => __( '' ),
212
+ 'cat' => __( '' ),
213
+ 'num' => __( '' ),
214
+ 'sort_by' => __( '' ),
215
+ 'asc_sort_order' => __( '' ),
216
+ 'title_link' => __( '' ),
217
+ 'excerpt' => __( '' ),
218
+ 'excerpt_length' => __( '' ),
219
+ 'comment_num' => __( '' ),
220
+ 'date' => __( '' ),
221
+ 'thumb' => __( '' ),
222
+ 'thumbTop' => __( '' ),
223
+ 'thumb_w' => __( '' ),
224
+ 'thumb_h' => __( '' ),
225
+ 'disable_css' => __( '' ),
226
+ 'hide_if_empty' => __( '' )
227
+ ) );
228
+
229
+ $title = $instance['title'];
230
+ $hide_title = $instance['hide_title'];
231
+ $cat = $instance['cat'];
232
+ $num = $instance['num'];
233
+ $sort_by = $instance['sort_by'];
234
+ $asc_sort_order = $instance['asc_sort_order'];
235
+ $title_link = $instance['title_link'];
236
+ $excerpt = $instance['excerpt'];
237
+ $excerpt_length = $instance['excerpt_length'];
238
+ $comment_num = $instance['comment_num'];
239
+ $date = $instance['date'];
240
+ $thumb = $instance['thumb'];
241
+ $thumbTop = $instance['thumbTop'];
242
+ $thumb_w = $instance['thumb_w'];
243
+ $thumb_h = $instance['thumb_h'];
244
+ $disable_css = $instance['disable_css'];
245
+ $hide_if_empty = $instance['hide_if_empty'];
246
+
247
+ ?>
248
+ <p>
249
+ <label for="<?php echo $this->get_field_id("title"); ?>">
250
+ <?php _e( 'Title' ); ?>:
251
+ <input class="widefat" id="<?php echo $this->get_field_id("title"); ?>" name="<?php echo $this->get_field_name("title"); ?>" type="text" value="<?php echo esc_attr($instance["title"]); ?>" />
252
+ </label>
253
+ </p>
254
+ <p>
255
+ <label for="<?php echo $this->get_field_id("hide_title"); ?>">
256
+ <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("hide_title"); ?>" name="<?php echo $this->get_field_name("hide_title"); ?>"<?php checked( (bool) $instance["hide_title"], true ); ?> />
257
+ <?php _e( 'Hide title' ); ?>
258
+ </label>
259
+ </p>
260
+ <p>
261
+ <label for="<?php echo $this->get_field_id("title_link"); ?>">
262
+ <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 ); ?> />
263
+ <?php _e( 'Make widget title link' ); ?>
264
+ </label>
265
+ </p>
266
+ <p>
267
+ <label>
268
+ <?php _e( 'Category' ); ?>:
269
+ <?php wp_dropdown_categories( array( 'name' => $this->get_field_name("cat"), 'selected' => $instance["cat"] ) ); ?>
270
+ </label>
271
+ </p>
272
+ <p>
273
+ <label for="<?php echo $this->get_field_id("num"); ?>">
274
+ <?php _e('Number of posts to show'); ?>:
275
+ <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' />
276
+ </label>
277
+ </p>
278
+ <p>
279
+ <label for="<?php echo $this->get_field_id("sort_by"); ?>">
280
+ <?php _e('Sort by'); ?>:
281
+ <select id="<?php echo $this->get_field_id("sort_by"); ?>" name="<?php echo $this->get_field_name("sort_by"); ?>">
282
+ <option value="date"<?php selected( $instance["sort_by"], "date" ); ?>>Date</option>
283
+ <option value="title"<?php selected( $instance["sort_by"], "title" ); ?>>Title</option>
284
+ <option value="comment_count"<?php selected( $instance["sort_by"], "comment_count" ); ?>>Number of comments</option>
285
+ <option value="rand"<?php selected( $instance["sort_by"], "rand" ); ?>>Random</option>
286
+ </select>
287
+ </label>
288
+ </p>
289
+ <p>
290
+ <label for="<?php echo $this->get_field_id("asc_sort_order"); ?>">
291
+ <input type="checkbox" class="checkbox"
292
+ id="<?php echo $this->get_field_id("asc_sort_order"); ?>"
293
+ name="<?php echo $this->get_field_name("asc_sort_order"); ?>"
294
+ <?php checked( (bool) $instance["asc_sort_order"], true ); ?> />
295
+ <?php _e( 'Reverse sort order (ascending)' ); ?>
296
+ </label>
297
+ </p>
298
+ <p>
299
+ <label for="<?php echo $this->get_field_id("excerpt"); ?>">
300
+ <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("excerpt"); ?>" name="<?php echo $this->get_field_name("excerpt"); ?>"<?php checked( (bool) $instance["excerpt"], true ); ?> />
301
+ <?php _e( 'Show post excerpt' ); ?>
302
+ </label>
303
+ </p>
304
+ <p>
305
+ <label for="<?php echo $this->get_field_id("excerpt_length"); ?>">
306
+ <?php _e( 'Excerpt length (in words):' ); ?>
307
+ </label>
308
+ <input style="text-align: center;" type="text" id="<?php echo $this->get_field_id("excerpt_length"); ?>" name="<?php echo $this->get_field_name("excerpt_length"); ?>" value="<?php echo $instance["excerpt_length"]; ?>" size="3" />
309
+ </p>
310
+ <p>
311
+ <label for="<?php echo $this->get_field_id("comment_num"); ?>">
312
+ <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("comment_num"); ?>" name="<?php echo $this->get_field_name("comment_num"); ?>"<?php checked( (bool) $instance["comment_num"], true ); ?> />
313
+ <?php _e( 'Show number of comments' ); ?>
314
+ </label>
315
+ </p>
316
+ <p>
317
+ <label for="<?php echo $this->get_field_id("date"); ?>">
318
+ <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("date"); ?>" name="<?php echo $this->get_field_name("date"); ?>"<?php checked( (bool) $instance["date"], true ); ?> />
319
+ <?php _e( 'Show post date' ); ?>
320
+ </label>
321
+ </p>
322
+ <?php if ( function_exists('the_post_thumbnail') && current_theme_supports("post-thumbnails") ) : ?>
323
+ <p>
324
+ <label for="<?php echo $this->get_field_id("thumb"); ?>">
325
+ <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("thumb"); ?>" name="<?php echo $this->get_field_name("thumb"); ?>"<?php checked( (bool) $instance["thumb"], true ); ?> />
326
+ <?php _e( 'Show post thumbnail' ); ?>
327
+ </label>
328
+ </p>
329
+ <p>
330
+ <label for="<?php echo $this->get_field_id("thumbTop"); ?>">
331
+ <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("thumbTop"); ?>" name="<?php echo $this->get_field_name("thumbTop"); ?>"<?php checked( (bool) $instance["thumbTop"], true ); ?> />
332
+ <?php _e( 'Thumbnail to top' ); ?>
333
+ </label>
334
+ </p>
335
+ <p>
336
+ <label>
337
+ <?php _e('Thumbnail dimensions (in pixels)'); ?>:<br />
338
+ <label for="<?php echo $this->get_field_id("thumb_w"); ?>">
339
+ Width: <input class="widefat" style="width:30%;" type="text" id="<?php echo $this->get_field_id("thumb_w"); ?>" name="<?php echo $this->get_field_name("thumb_w"); ?>" value="<?php echo $instance["thumb_w"]; ?>" />
340
+ </label>
341
+
342
+ <label for="<?php echo $this->get_field_id("thumb_h"); ?>">
343
+ Height: <input class="widefat" style="width:30%;" type="text" id="<?php echo $this->get_field_id("thumb_h"); ?>" name="<?php echo $this->get_field_name("thumb_h"); ?>" value="<?php echo $instance["thumb_h"]; ?>" />
344
+ </label>
345
+ </label>
346
+ </p>
347
+ <?php endif; ?>
348
+ <p>
349
+ <label for="<?php echo $this->get_field_id("disable_css"); ?>">
350
+ <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("disable_css"); ?>" name="<?php echo $this->get_field_name("disable_css"); ?>"<?php checked( (bool) $instance["disable_css"], true ); ?> />
351
+ <?php _e( 'Disable widget CSS' ); ?>
352
+ </label>
353
+ </p>
354
+ <p>
355
+ <label for="<?php echo $this->get_field_id("hide_if_empty"); ?>">
356
+ <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("hide_if_empty"); ?>" name="<?php echo $this->get_field_name("hide_if_empty"); ?>"<?php checked( (bool) $instance["hide_if_empty"], true ); ?> />
357
+ <?php _e( 'Hide if empty' ); ?>
358
+ </label>
359
+ </p>
360
+ <?php
361
+ }
362
+ }
363
+
364
+ add_action( 'widgets_init', create_function('', 'return register_widget("CategoryPosts");') );
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: mkrdip, kometschuh
3
  Donate link: http://mkrdip.me/donate
4
  Tags: category, posts, widget, single category widget, posts widget, category recent posts
5
  Requires at least: 2.8
6
- Tested up to: 4.3.0
7
- Stable tag: 4.1.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -19,13 +19,15 @@ Category Posts Widget is a light widget designed to do one thing and do it well:
19
  * Option to change ordering of posts.
20
  * Option to show post thumbnail & set dimension by width & height.
21
  * Option to put thumbnail on top
 
22
  * Set how many posts to show.
23
  * Set which category the posts should come form.
24
  * Option to show the post excerpt and how long the excerpt should be.
25
  * Option to show the post date.
26
  * Option to show the comment count.
27
  * Option to make the widget title link to the category page.
28
- * Option to hide the title
 
29
  * Multiple widgets.
30
 
31
  = Contribute =
@@ -63,6 +65,10 @@ Automatic installation is the easiest option as WordPress handles the file trans
63
 
64
  Please use the option: "Disable widget CSS".
65
 
 
 
 
 
66
  == Screenshots ==
67
 
68
  1. The widget configuration dialog.
@@ -70,27 +76,31 @@ Please use the option: "Disable widget CSS".
70
 
71
  == Changelog ==
72
 
 
 
 
 
73
  4.1.2
74
 
75
  * Fixed hide title bug.
76
 
77
  4.1.1
78
 
79
- * Added option to put thumbnail on top
80
- * Added option to hide the title
81
  * Fixed no background bug.
82
 
83
  4.1.0
84
 
85
- * Added PHP5 Constructor
86
- * Added Option to allow/disallow widget CSS
87
- * Now, compatible with WordPress 4.3
88
  * Meet new plugin author [kometschuh](https://profiles.wordpress.org/kometschuh)
89
 
90
  4.0
91
 
92
- * Added CSS file for post styling
93
- * Now compaitable with latest versions of WordPress
94
 
95
  3.3
96
 
@@ -114,7 +124,7 @@ Please use the option: "Disable widget CSS".
114
 
115
  2.3
116
 
117
- * Really tried to fix bug where wp_query global was getting over written by manually instantiating a WP_Query object
118
 
119
  2.1
120
 
3
  Donate link: http://mkrdip.me/donate
4
  Tags: category, posts, widget, single category widget, posts widget, category recent posts
5
  Requires at least: 2.8
6
+ Tested up to: 4.3.1
7
+ Stable tag: 4.1.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
19
  * Option to change ordering of posts.
20
  * Option to show post thumbnail & set dimension by width & height.
21
  * Option to put thumbnail on top
22
+ * Option to disable widget CSS.
23
  * Set how many posts to show.
24
  * Set which category the posts should come form.
25
  * Option to show the post excerpt and how long the excerpt should be.
26
  * Option to show the post date.
27
  * Option to show the comment count.
28
  * Option to make the widget title link to the category page.
29
+ * Option to hide the title.
30
+ * Option to hide widget, if category have currently no posts.
31
  * Multiple widgets.
32
 
33
  = Contribute =
65
 
66
  Please use the option: "Disable widget CSS".
67
 
68
+ = I want the title as a link pointing to the selected Categorie page? =
69
+
70
+ Enable the check box "Make widget title link".
71
+
72
  == Screenshots ==
73
 
74
  1. The widget configuration dialog.
76
 
77
  == Changelog ==
78
 
79
+ 4.1.3
80
+
81
+ * Added option to hide widget, if category have currently no posts.
82
+
83
  4.1.2
84
 
85
  * Fixed hide title bug.
86
 
87
  4.1.1
88
 
89
+ * Added option to put thumbnail on top.
90
+ * Added option to show/hide the title.
91
  * Fixed no background bug.
92
 
93
  4.1.0
94
 
95
+ * Added PHP5 Constructor.
96
+ * Added Option to allow/disallow widget CSS.
97
+ * Now, compatible with WordPress 4.3.
98
  * Meet new plugin author [kometschuh](https://profiles.wordpress.org/kometschuh)
99
 
100
  4.0
101
 
102
+ * Added CSS file for post styling .
103
+ * Now compatible with latest versions of WordPress.
104
 
105
  3.3
106
 
124
 
125
  2.3
126
 
127
+ * Really tried to fix bug where wp_query global was getting over written by manually instantiating a WP_Query object.
128
 
129
  2.1
130