Category Posts Widget - Version 4.1.6

Version Description

  • April 13th 2016 =
  • Add option CSS cropping for thumbnails.
  • Add option to set mouse hover effects for post thumbnail.
  • Add option to change the excerpt more text.
  • Add option to allow links in the excerpt
  • Add filter 'widget_title' for the title
  • Add option to hide post titles.
Download this release

Release Info

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

Code changes from version 4.1.5 to 4.1.6

Files changed (4) hide show
  1. cat-posts.css +86 -2
  2. cat-posts.php +384 -99
  3. js/admin/category-posts-widget.js +4 -4
  4. readme.txt +16 -7
cat-posts.css CHANGED
@@ -1,7 +1,27 @@
1
  /*
2
  Default CSS Styles for the Category Posts Widget plugin
3
- Version: 4.1.5
4
  */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  .cat-post-title {
6
  font-size: 15px;
7
  font-size: 0.9375rem;
@@ -24,9 +44,12 @@ Version: 4.1.5
24
  .cat-post-author {
25
  margin-bottom: 0;
26
  }
 
 
 
27
  .cat-post-thumbnail img {
28
- float: left;
29
  margin: 5px 10px 5px 0;
 
30
  }
31
  .cat-post-item {
32
  border-bottom: 1px solid #ccc;
@@ -44,3 +67,64 @@ Version: 4.1.5
44
  .cat-post-item:last-child {
45
  border-bottom: none;
46
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  /*
2
  Default CSS Styles for the Category Posts Widget plugin
3
+ Version: 4.1.6
4
  */
5
+
6
+ /*--------------------------------------------------------------
7
+ >>> TABLE OF CONTENTS:
8
+ ----------------------------------------------------------------
9
+ 1.0 Normalise
10
+ 2.0 General
11
+ 3.0 CSS cropping
12
+ 4.0 Thumbnail hover effects
13
+ --------------------------------------------------------------*/
14
+
15
+ /*--------------------------------------------------------------
16
+ 1.0 Normalise
17
+ --------------------------------------------------------------*/
18
+ .cat-post-item span.cat-post-css-cropping img {
19
+ max-width: initial;
20
+ max-height: initial;
21
+ }
22
+ /*--------------------------------------------------------------
23
+ 2.0 General
24
+ --------------------------------------------------------------*/
25
  .cat-post-title {
26
  font-size: 15px;
27
  font-size: 0.9375rem;
44
  .cat-post-author {
45
  margin-bottom: 0;
46
  }
47
+ .cat-post-thumbnail {
48
+ display: block;
49
+ }
50
  .cat-post-thumbnail img {
 
51
  margin: 5px 10px 5px 0;
52
+ float: left;
53
  }
54
  .cat-post-item {
55
  border-bottom: 1px solid #ccc;
67
  .cat-post-item:last-child {
68
  border-bottom: none;
69
  }
70
+ /*--------------------------------------------------------------
71
+ 3.0 CSS cropping
72
+ --------------------------------------------------------------*/
73
+ .cat-post-item .cat-post-css-cropping span {
74
+ float: left;
75
+ margin: 5px 10px 5px 0;
76
+ }
77
+ /*--------------------------------------------------------------
78
+ 4.0 Thumbnail hover effects
79
+ --------------------------------------------------------------*/
80
+ /* For White, Dark, Scale */
81
+ li a.cat-post-white,
82
+ li a.cat-post-dark,
83
+ li a.cat-post-scale {
84
+ background-color: black;
85
+ display: inline-block;
86
+ float: left;
87
+ margin: 5px 10px 5px 0;
88
+ }
89
+ li.cat-post-item a.cat-post-white span,
90
+ li.cat-post-item a.cat-post-dark span,
91
+ li.cat-post-item a.cat-post-scale span{
92
+ margin: 0;
93
+ }
94
+ li a.cat-post-white img,
95
+ li a.cat-post-dark img,
96
+ li a.cat-post-scale img {
97
+ margin: 0;
98
+ padding-bottom: 0 !important;
99
+ }
100
+ li a.cat-post-white img:hover,
101
+ li a.cat-post-dark img:hover {
102
+ opacity: 0.8;
103
+ }
104
+ /* Only for White */
105
+ li a.cat-post-white {
106
+ background-color: white;
107
+ }
108
+ /* Only for Dark */
109
+ li a.cat-post-dark {
110
+ background-color: black;
111
+ }
112
+ /* Only for Scale */
113
+ li a.cat-post-scale {
114
+ overflow: hidden;
115
+ }
116
+ li a.cat-post-scale.cat-post-css-cropping span {
117
+ margin: 0;
118
+ overflow: initial;
119
+ }
120
+ li a.cat-post-scale img {
121
+ -webkit-transition: all 400ms;
122
+ -moz-transition: all 400ms;
123
+ -o-transition: all 400ms;
124
+ transition: all 400ms;
125
+ }
126
+ li a.cat-post-scale img:hover {
127
+ -webkit-transform: scale(1.1, 1.1);
128
+ -ms-transform: scale(1.1, 1.1);
129
+ transform: scale(1.1, 1.1);
130
+ }
cat-posts.php CHANGED
@@ -4,22 +4,24 @@ 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.5
8
  Author URI: http://mkrdip.me
9
  */
10
 
11
  // Don't call the file directly
12
  if ( !defined( 'ABSPATH' ) ) exit;
13
 
 
 
 
 
14
  /*
15
- Check if CSS needs to be enqueued by traversing all active widgets on the page
16
- and checking if they all have disabled CSS.
17
-
18
- Return: false if CSS should not be enqueued, true if it should
19
  */
20
- function category_posts_should_enqueue($id_base,$class) {
21
  global $wp_registered_widgets;
22
- $ret = false;
23
  $sidebars_widgets = wp_get_sidebars_widgets();
24
 
25
  if ( is_array($sidebars_widgets) ) {
@@ -34,14 +36,53 @@ function category_posts_should_enqueue($id_base,$class) {
34
  if ( $widget_base == $id_base ) {
35
  $widgetclass = new $class();
36
  $allsettings = $widgetclass->get_settings();
37
- $settings = $allsettings[str_replace($widget_base.'-','',$widget)];
38
- if (!isset($settings['disable_css'])) // checks if css disable is not set
39
- $ret = true;
40
  }
41
  }
42
  }
43
  }
44
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  return $ret;
46
  }
47
 
@@ -52,10 +93,25 @@ function category_posts_should_enqueue($id_base,$class) {
52
  */
53
  add_action( 'wp_enqueue_scripts', 'category_posts_widget_styles' );
54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  function category_posts_widget_styles() {
56
  $enqueue = category_posts_should_enqueue('category-posts','CategoryPosts');
57
  if ($enqueue) {
58
- wp_register_style( 'category-posts', plugins_url( 'category-posts/cat-posts.css' ) );
59
  wp_enqueue_style( 'category-posts' );
60
  }
61
  }
@@ -129,12 +185,49 @@ function category_posts_admin_styles() {
129
  * Add JS to control open and close the widget section
130
  *
131
  */
132
- add_action( 'admin_enqueue_scripts', 'category_posts_admin_scripts', 100 );
133
 
134
- function category_posts_admin_scripts() {
135
  // widget script
136
- wp_register_script( 'category-posts-admin-js', plugins_url( 'category-posts/js/admin/category-posts-widget.js' ),array('jquery'),'4.1.2',true );
137
- wp_enqueue_script( 'category-posts-admin-js' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  }
139
 
140
  /**
@@ -149,10 +242,132 @@ class CategoryPosts extends WP_Widget {
149
  parent::__construct('category-posts', __('Category Posts','categoryposts'), $widget_ops);
150
  }
151
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
  // Displays category posts widget on blog.
153
  function widget($args, $instance) {
154
 
155
  extract( $args );
 
156
 
157
  // If not title, use the name of the category.
158
  if( !$instance["title"] ) {
@@ -197,10 +412,23 @@ class CategoryPosts extends WP_Widget {
197
 
198
  if ( !isset ( $instance["hide_if_empty"] ) || $cat_posts->have_posts() ) {
199
 
200
- // Excerpt length filter
 
 
201
  $new_excerpt_length = create_function('$length', "return " . $instance["excerpt_length"] . ";");
202
- if ( $instance["excerpt_length"] > 0 )
203
- add_filter('excerpt_length', $new_excerpt_length);
 
 
 
 
 
 
 
 
 
 
 
204
 
205
  echo $before_widget;
206
 
@@ -208,43 +436,46 @@ class CategoryPosts extends WP_Widget {
208
  if( !isset ( $instance["hide_title"] ) ) {
209
  echo $before_title;
210
  if( isset ( $instance["title_link"] ) ) {
211
- echo '<a href="' . get_category_link($instance["cat"]) . '">' . $instance["title"] . '</a>';
212
  } else {
213
- echo $instance["title"];
214
  }
215
  echo $after_title;
216
  }
217
 
218
  // Post list
219
  echo "<ul>\n";
220
-
 
 
 
 
221
  while ( $cat_posts->have_posts() )
222
  {
223
  $cat_posts->the_post(); ?>
224
 
225
- <li <?php if( !isset( $instance['disable_css'] ) ) {
226
- echo "class=\"cat-post-item";
227
- if ( is_single(get_the_title() ) ) { echo " cat-post-current"; }
228
- echo "\"";
229
- } ?> >
 
 
230
 
231
- <?php
 
 
232
  if( isset( $instance["thumbTop"] ) ) :
233
- if ( current_theme_supports("post-thumbnails") &&
234
- isset( $instance["thumb"] ) &&
235
- has_post_thumbnail() ) : ?>
236
- <a <?php if( !isset( $instance['disable_css'] ) ) { echo "class=\"cat-post-thumbnail\""; } ?>
237
- href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
238
- <?php the_post_thumbnail( array($instance['thumb_w'],$instance['thumb_h'])); ?>
239
- </a>
240
- <?php endif;
241
- endif; ?>
242
 
243
- <a class="post-title <?php if( !isset( $instance['disable_css'] ) ) { echo " cat-post-title"; } ?>"
244
- href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?>
245
- </a>
 
 
246
 
247
- <?php if ( isset( $instance['date'] ) ) : ?>
248
  <?php if ( isset( $instance['date_format'] ) && strlen( trim( $instance['date_format'] ) ) > 0 ) { $date_format = $instance['date_format']; } else { $date_format = "j M Y"; } ?>
249
  <p class="post-date <?php if( !isset( $instance['disable_css'] ) ) { echo "cat-post-date"; } ?>">
250
  <?php if( isset ( $instance["date_link"] ) ) { ?> <a href="<?php the_permalink(); ?>"><?php } ?>
@@ -252,16 +483,10 @@ class CategoryPosts extends WP_Widget {
252
  <?php if( isset ( $instance["date_link"] ) ) { echo "</a>"; } ?>
253
  </p>
254
  <?php endif;
255
-
 
256
  if( !isset( $instance["thumbTop"] ) ) :
257
- if ( current_theme_supports("post-thumbnails") &&
258
- isset( $instance["thumb"] ) &&
259
- has_post_thumbnail() ) : ?>
260
- <a <?php if( !isset( $instance['disable_css'] ) ) { echo "class=\"cat-post-thumbnail\""; } ?>
261
- href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
262
- <?php the_post_thumbnail( array($instance['thumb_w'],$instance['thumb_h'])); ?>
263
- </a>
264
- <?php endif;
265
  endif;
266
 
267
  if ( isset( $instance['excerpt'] ) ) :
@@ -272,7 +497,7 @@ class CategoryPosts extends WP_Widget {
272
  <p class="comment-num <?php if( !isset( $instance['disable_css'] ) ) { echo "cat-post-comment-num"; } ?>">
273
  (<?php comments_number(); ?>)
274
  </p>
275
- <?php endif;
276
 
277
  if ( isset( $instance['author'] ) ) : ?>
278
  <p class="post-author <?php if( !isset( $instance['disable_css'] ) ) { echo "cat-post-author"; } ?>">
@@ -295,7 +520,10 @@ class CategoryPosts extends WP_Widget {
295
  echo $after_widget;
296
 
297
  remove_filter('excerpt_length', $new_excerpt_length);
298
-
 
 
 
299
  wp_reset_postdata();
300
 
301
  } // END if
@@ -324,14 +552,17 @@ class CategoryPosts extends WP_Widget {
324
  'title' => '',
325
  'hide_title' => '',
326
  'cat' => '',
327
- 'num' => '',
328
  'sort_by' => '',
329
  'asc_sort_order' => '',
330
  'exclude_current_post' => '',
331
  'title_link' => '',
332
  'footer_link' => '',
 
333
  'excerpt' => '',
334
- 'excerpt_length' => '',
 
 
335
  'comment_num' => '',
336
  'author' => '',
337
  'date' => '',
@@ -342,6 +573,8 @@ class CategoryPosts extends WP_Widget {
342
  'hideNoThumb' => '',
343
  'thumb_w' => '',
344
  'thumb_h' => '',
 
 
345
  'disable_css' => '',
346
  'hide_if_empty' => ''
347
  ) );
@@ -355,8 +588,11 @@ class CategoryPosts extends WP_Widget {
355
  $exclude_current_post = $instance['exclude_current_post'];
356
  $title_link = $instance['title_link'];
357
  $footer_link = $instance['footer_link'];
 
358
  $excerpt = $instance['excerpt'];
359
  $excerpt_length = $instance['excerpt_length'];
 
 
360
  $comment_num = $instance['comment_num'];
361
  $author = $instance['author'];
362
  $date = $instance['date'];
@@ -367,13 +603,38 @@ class CategoryPosts extends WP_Widget {
367
  $hideNoThumb = $instance['hideNoThumb'];
368
  $thumb_w = $instance['thumb_w'];
369
  $thumb_h = $instance['thumb_h'];
 
 
370
  $disable_css = $instance['disable_css'];
371
  $hide_if_empty = $instance['hide_if_empty'];
372
 
373
  ?>
374
  <div class="category-widget-cont">
375
- <h4 class="open"><?php _e('Filter','categoryposts');?></h4>
376
- <div class="open">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
377
  <p>
378
  <label>
379
  <?php _e( 'Category','categoryposts' ); ?>:
@@ -412,27 +673,12 @@ class CategoryPosts extends WP_Widget {
412
  <?php _e( 'Exclude current post','categoryposts' ); ?>
413
  </label>
414
  </p>
415
- </div>
416
- <h4><?php _e('Title','categoryposts')?></h4>
417
- <div>
418
- <p>
419
- <label for="<?php echo $this->get_field_id("title"); ?>">
420
- <?php _e( 'Title','categoryposts' ); ?>:
421
- <input class="widefat" style="width:80%;" 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"]); ?>" />
422
- </label>
423
- </p>
424
- <p>
425
- <label for="<?php echo $this->get_field_id("title_link"); ?>">
426
- <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 ); ?> />
427
- <?php _e( 'Make widget title link','categoryposts' ); ?>
428
- </label>
429
- </p>
430
- <p>
431
- <label for="<?php echo $this->get_field_id("hide_title"); ?>">
432
- <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 ); ?> />
433
- <?php _e( 'Hide title','categoryposts' ); ?>
434
- </label>
435
- </p>
436
  </div>
437
  <?php if ( current_theme_supports("post-thumbnails") ) : ?>
438
  <h4><?php _e('Thumbnails','categoryposts')?></h4>
@@ -443,16 +689,10 @@ class CategoryPosts extends WP_Widget {
443
  <?php _e( 'Show post thumbnail','categoryposts' ); ?>
444
  </label>
445
  </p>
446
- <p>
447
- <label for="<?php echo $this->get_field_id("hideNoThumb"); ?>">
448
- <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("hideNoThumb"); ?>" name="<?php echo $this->get_field_name("hideNoThumb"); ?>"<?php checked( (bool) $instance["hideNoThumb"], true ); ?> />
449
- <?php _e( 'Hide posts which have no thumbnail','categoryposts' ); ?>
450
- </label>
451
- </p>
452
  <p>
453
  <label for="<?php echo $this->get_field_id("thumbTop"); ?>">
454
  <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 ); ?> />
455
- <?php _e( 'Thumbnail to top','categoryposts' ); ?>
456
  </label>
457
  </p>
458
  <p>
@@ -466,11 +706,34 @@ class CategoryPosts extends WP_Widget {
466
  <?php _e('Height:','categoryposts')?> <input class="widefat" style="width:30%;" type="number" min="1" id="<?php echo $this->get_field_id("thumb_h"); ?>" name="<?php echo $this->get_field_name("thumb_h"); ?>" value="<?php echo $instance["thumb_h"]; ?>" />
467
  </label>
468
  </label>
469
- </p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
470
  </div>
471
  <?php endif; ?>
472
  <h4><?php _e('Post details','categoryposts')?></h4>
473
  <div>
 
 
 
 
 
 
474
  <p>
475
  <label for="<?php echo $this->get_field_id("excerpt"); ?>">
476
  <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 ); ?> />
@@ -481,8 +744,20 @@ class CategoryPosts extends WP_Widget {
481
  <label for="<?php echo $this->get_field_id("excerpt_length"); ?>">
482
  <?php _e( 'Excerpt length (in words):','categoryposts' ); ?>
483
  </label>
484
- <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" />
485
- </p>
 
 
 
 
 
 
 
 
 
 
 
 
486
  <p>
487
  <label for="<?php echo $this->get_field_id("date"); ?>">
488
  <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 ); ?> />
@@ -514,33 +789,43 @@ class CategoryPosts extends WP_Widget {
514
  </label>
515
  </p>
516
  </div>
517
- <h4><?php _e('Footer','categoryposts')?></h4>
518
- <div>
519
- <p>
520
- <label for="<?php echo $this->get_field_id("footer_link"); ?>">
521
- <?php _e( 'Footer link text','categoryposts' ); ?>:
522
- <input class="widefat" style="width:60%;" placeholder="<?php _e('... more by this topic','categoryposts')?>" id="<?php echo $this->get_field_id("footer_link"); ?>" name="<?php echo $this->get_field_name("footer_link"); ?>" type="text" value="<?php echo esc_attr($instance["footer_link"]); ?>" />
523
- </label>
524
- </p>
525
- </div>
526
- <h4><?php _e('General styling','categoryposts')?></h4>
527
  <div>
528
  <p>
529
  <label for="<?php echo $this->get_field_id("disable_css"); ?>">
530
  <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 ); ?> />
531
- <?php _e( 'Disable widget CSS','categoryposts' ); ?>
532
  </label>
533
  </p>
534
  <p>
535
  <label for="<?php echo $this->get_field_id("hide_if_empty"); ?>">
536
  <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 ); ?> />
537
- <?php _e( 'Hide if empty','categoryposts' ); ?>
538
  </label>
539
  </p>
540
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
541
  </div>
542
  <?php
543
  }
544
  }
545
 
546
- add_action( 'widgets_init', create_function('', 'return register_widget("CategoryPosts");') );
 
 
 
 
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.6
8
  Author URI: http://mkrdip.me
9
  */
10
 
11
  // Don't call the file directly
12
  if ( !defined( 'ABSPATH' ) ) exit;
13
 
14
+ define( 'CAT_POST_PLUGINURL', plugins_url(basename( dirname(__FILE__))) . "/");
15
+ define( 'CAT_POST_PLUGINPATH', dirname(__FILE__) . "/");
16
+ define( 'CAT_POST_VERSION', "4.1.5");
17
+
18
  /*
19
+ * Iterate over all the widgets active at the page and call the callback for them
20
+ *
21
+ * callback - accepts the widget settings, return true to continue iteration or false to stop
 
22
  */
23
+ function category_posts_iterator($id_base,$class,$callback) {
24
  global $wp_registered_widgets;
 
25
  $sidebars_widgets = wp_get_sidebars_widgets();
26
 
27
  if ( is_array($sidebars_widgets) ) {
36
  if ( $widget_base == $id_base ) {
37
  $widgetclass = new $class();
38
  $allsettings = $widgetclass->get_settings();
39
+ $settings = isset($allsettings[str_replace($widget_base.'-','',$widget)]) ? $allsettings[str_replace($widget_base.'-','',$widget)] : false;
40
+ if (!$callback($settings))
41
+ return;
42
  }
43
  }
44
  }
45
  }
46
  }
47
+ }
48
+
49
+ /*
50
+ Check if CSS needs to be added to support cropping by traversing all active widgets on the page
51
+ and checking if any has cropping enabled.
52
+
53
+ Return: false if cropping is not active, false otherwise
54
+ */
55
+ function category_posts_cropping_active($id_base,$class) {
56
+ $ret = false;
57
+
58
+ category_posts_iterator($id_base, $class, function ($settings) use (&$ret) {
59
+ if (isset($settings['use_css_cropping'])) { // checks if cropping is active
60
+ $ret = true;
61
+ return false; // stop iterator
62
+ } else
63
+ return true; // continue iteration to next widget
64
+ });
65
+
66
+ return $ret;
67
+ }
68
+
69
+ /*
70
+ Check if CSS needs to be enqueued by traversing all active widgets on the page
71
+ and checking if they all have disabled CSS.
72
+
73
+ Return: false if CSS should not be enqueued, true if it should
74
+ */
75
+ function category_posts_should_enqueue($id_base,$class) {
76
+ $ret = false;
77
+
78
+ category_posts_iterator($id_base, $class, function ($settings) use (&$ret) {
79
+ if (!isset($settings['disable_css'])) { // checks if css disable is not set
80
+ $ret = true;
81
+ return false; // stop iterator
82
+ } else
83
+ return true; // continue iteration to next widget
84
+ });
85
+
86
  return $ret;
87
  }
88
 
93
  */
94
  add_action( 'wp_enqueue_scripts', 'category_posts_widget_styles' );
95
 
96
+ function category_posts_wp_head() {
97
+ if (category_posts_cropping_active('category-posts','CategoryPosts')) {
98
+ ?>
99
+ <style type="text/css">
100
+ .cat-post-item .cat-post-css-cropping span {
101
+ overflow: hidden;
102
+ display:inline-block;
103
+ }
104
+ </style>
105
+ <?php
106
+ }
107
+ }
108
+
109
+ add_action('wp_head','category_posts_wp_head');
110
+
111
  function category_posts_widget_styles() {
112
  $enqueue = category_posts_should_enqueue('category-posts','CategoryPosts');
113
  if ($enqueue) {
114
+ wp_register_style( 'category-posts', CAT_POST_PLUGINURL . 'cat-posts.css' );
115
  wp_enqueue_style( 'category-posts' );
116
  }
117
  }
185
  * Add JS to control open and close the widget section
186
  *
187
  */
188
+ add_action( 'admin_enqueue_scripts', 'category_posts_admin_scripts', 10,1 );
189
 
190
+ function category_posts_admin_scripts($hook) {
191
  // widget script
192
+ if ($hook == 'widgets.php') { // enqueue only for widget admin and customizer
193
+ wp_register_script( 'category-posts-admin-js', CAT_POST_PLUGINURL . 'js/admin/category-posts-widget.js',array('jquery'),CAT_POST_VERSION,true );
194
+ wp_enqueue_script( 'category-posts-admin-js' );
195
+ }
196
+ }
197
+
198
+ /**
199
+ * Get image size
200
+ *
201
+ * $thumb_w, $thumb_h - the width and height of the thumbnail in the widget settings
202
+ * $image_w,$image_h - the width and height of the actual image being displayed
203
+ *
204
+ * return: an array with the width and height of the element containing the image
205
+ */
206
+ function category_posts_get_image_size( $thumb_w,$thumb_h,$image_w,$image_h) {
207
+
208
+ $image_size = array('image_h' => $thumb_h, 'image_w' => $thumb_w, 'marginAttr' => '', 'marginVal' => '');
209
+ $relation_thumbnail = $thumb_w / $thumb_h;
210
+ $relation_cropped = $image_w / $image_h;
211
+
212
+ if ($relation_thumbnail < $relation_cropped) {
213
+ // crop left and right site
214
+ // thumbnail width/height ration is smaller, need to inflate the height of the image to thumb height
215
+ // and adjust width to keep aspect ration of image
216
+ $image_size['image_h'] = $thumb_h;
217
+ $image_size['image_w'] = $thumb_h / $image_h * $image_w;
218
+ $image_size['marginAttr'] = 'margin-left';
219
+ $image_size['marginVal'] = ($image_size['image_w'] - $thumb_w) / 2;
220
+ } else {
221
+ // crop top and bottom
222
+ // thumbnail width/height ration is bigger, need to inflate the width of the image to thumb width
223
+ // and adjust height to keep aspect ration of image
224
+ $image_size['image_w'] = $thumb_w;
225
+ $image_size['image_h'] = $thumb_w / $image_w * $image_h;
226
+ $image_size['marginAttr'] = 'margin-top';
227
+ $image_size['marginVal'] = ($image_size['image_h'] - $thumb_h) / 2;
228
+ }
229
+
230
+ return $image_size;
231
  }
232
 
233
  /**
242
  parent::__construct('category-posts', __('Category Posts','categoryposts'), $widget_ops);
243
  }
244
 
245
+ /*
246
+ override the thumbnail htmo to insert cropping when needed
247
+ */
248
+ function post_thumbnail_html($html, $post_id, $post_thumbnail_id, $size, $attr){
249
+ if ( empty($this->instance['thumb_w']) || empty($this->instance['thumb_w']))
250
+ return $html; // bail out if no full dimensions defined
251
+
252
+ $meta = image_get_intermediate_size($post_thumbnail_id,$size);
253
+ $origfile = get_attached_file( $post_thumbnail_id, true); // the location of the full file
254
+ $file = dirname($origfile) .'/'.$meta['file']; // the location of the file displayed as thumb
255
+ list( $width, $height ) = getimagesize($file); // get actual size of the thumb file
256
+
257
+ if ($width / $height == $this->instance['thumb_w'] / $this->instance['thumb_h']) {
258
+ // image is same ratio as asked for, nothing to do here as the browser will handle it correctly
259
+ ;
260
+ } else if (isset($this->instance['use_css_cropping'])) {
261
+ $image = category_posts_get_image_size($this->instance['thumb_w'],$this->instance['thumb_h'],$width,$height);
262
+
263
+ // replace srcset
264
+ $array = array();
265
+ preg_match( '/width="([^"]*)"/i', $html, $array ) ;
266
+ $pattern = "/".$array[1]."w/";
267
+ $html = preg_replace($pattern, $image['image_w']."w", $html);
268
+ // replace size
269
+ $pattern = "/".$array[1]."px/";
270
+ $html = preg_replace($pattern, $image['image_w']."px", $html);
271
+ // replace width
272
+ $pattern = "/width=\"[0-9]*\"/";
273
+ $html = preg_replace($pattern, "width='".$image['image_w']."'", $html);
274
+ // replace height
275
+ $pattern = "/height=\"[0-9]*\"/";
276
+ $html = preg_replace($pattern, "height='".$image['image_h']."'", $html);
277
+ // set margin
278
+ $html = str_replace('<img ','<img style="'.$image['marginAttr'].':-'.$image['marginVal'].'px;height:'.$image['image_h']
279
+ .'px;clip:rect(auto,'.($this->instance['thumb_w']+$image['marginVal']).'px,auto,'.$image['marginVal']
280
+ .'px);width:auto;max-width:initial;" ',$html);
281
+ // wrap span
282
+ $html = '<span style="width:'.$this->instance['thumb_w'].'px;height:'.$this->instance['thumb_h'].'px;">'
283
+ .$html.'</span>';
284
+ } else {
285
+ // if use_css_cropping not used
286
+ // no interface changes: leave without change
287
+ }
288
+ return $html;
289
+ }
290
+
291
+ /*
292
+ wrapper to execute the the_post_thumbnail with filters
293
+ */
294
+ function the_post_thumbnail($size= 'post-thumbnail',$attr='') {
295
+ add_filter('post_thumbnail_html',array($this,'post_thumbnail_html'),1,5);
296
+ the_post_thumbnail($size,$attr);
297
+ remove_filter('post_thumbnail_html',array($this,'post_thumbnail_html'),1,5);
298
+ }
299
+
300
+ /**
301
+ * Excerpt more link filter
302
+ */
303
+ function excerpt_more_filter($more) {
304
+ global $post;
305
+ return ' <a class="cat-post-excerpt-more" href="'. get_permalink($post->ID) . '">' . $this->instance["excerpt_more_text"] . '</a>';
306
+ }
307
+
308
+ /**
309
+ * Excerpt allow HTML
310
+ */
311
+ function allow_html_excerpt($text) {
312
+ global $post, $wp_filter;
313
+ $new_excerpt_length = ( isset($this->instance["excerpt_length"]) && $this->instance["excerpt_length"] > 0 ) ? $this->instance["excerpt_length"] : 55;
314
+ if ( '' == $text ) {
315
+ $text = get_the_content('');
316
+ $text = strip_shortcodes( $text );
317
+ $text = apply_filters('the_content', $text);
318
+ $text = str_replace('\]\]\>', ']]&gt;', $text);
319
+ $text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
320
+ $text = strip_tags($text, '<a>');
321
+ $excerpt_length = $new_excerpt_length;
322
+
323
+ if( !empty($this->instance["excerpt_more_text"]) ) {
324
+ $excerpt_more = $this->excerpt_more_filter($this->instance["excerpt_more_text"]);
325
+ }else if($filterName = key($wp_filter['excerpt_more'][10])) {
326
+ $excerpt_more = $wp_filter['excerpt_more'][10][$filterName]['function'](0);
327
+ }else {
328
+ $excerpt_more = '[...]';
329
+ }
330
+
331
+ $words = explode(' ', $text, $excerpt_length + 1);
332
+ if (count($words)> $excerpt_length) {
333
+ array_pop($words);
334
+ array_push($words, $excerpt_more);
335
+ $text = implode(' ', $words);
336
+ }
337
+ }
338
+
339
+ return '<p>' . $text . '</p>';
340
+ }
341
+
342
+ /*
343
+ Show the thumb of the current post
344
+ */
345
+ function show_thumb() {
346
+ if ( current_theme_supports("post-thumbnails") &&
347
+ isset( $this->instance["thumb"] ) &&
348
+ has_post_thumbnail() ) : ?>
349
+ <a <?php
350
+ $use_css_cropping = isset($this->instance['use_css_cropping']) ? "cat-post-css-cropping" : "";
351
+ if( !isset( $this->instance['disable_css'] )) {
352
+ if( isset($this->instance['thumb_hover'] )) {
353
+ echo "class=\"cat-post-thumbnail " . $use_css_cropping ." cat-post-" . $this->instance['thumb_hover'] . "\"";
354
+ } else {
355
+ echo "class=\"cat-post-thumbnail " . $use_css_cropping . "\"";
356
+ }
357
+ } ?>
358
+ href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
359
+ <?php
360
+ $this->the_post_thumbnail( array($this->instance['thumb_w'],$this->instance['thumb_h']));
361
+ ?>
362
+ </a>
363
+ <?php endif;
364
+ }
365
+
366
  // Displays category posts widget on blog.
367
  function widget($args, $instance) {
368
 
369
  extract( $args );
370
+ $this->instance = $instance;
371
 
372
  // If not title, use the name of the category.
373
  if( !$instance["title"] ) {
412
 
413
  if ( !isset ( $instance["hide_if_empty"] ) || $cat_posts->have_posts() ) {
414
 
415
+ /**
416
+ * Excerpt length filter
417
+ */
418
  $new_excerpt_length = create_function('$length', "return " . $instance["excerpt_length"] . ";");
419
+ if ( $instance["excerpt_length"] > 0 ) {
420
+ add_filter('excerpt_length', $new_excerpt_length);
421
+ }
422
+
423
+ if( isset($instance["excerpt_more_text"]) && ltrim($instance["excerpt_more_text"]) != '' )
424
+ {
425
+ add_filter('excerpt_more', array($this,'excerpt_more_filter'));
426
+ }
427
+
428
+ if( isset( $instance['excerpt_allow_html'] ) ) {
429
+ remove_filter('get_the_excerpt', 'wp_trim_excerpt');
430
+ add_filter('the_excerpt', array($this,'allow_html_excerpt'));
431
+ }
432
 
433
  echo $before_widget;
434
 
436
  if( !isset ( $instance["hide_title"] ) ) {
437
  echo $before_title;
438
  if( isset ( $instance["title_link"] ) ) {
439
+ echo '<a href="' . get_category_link($instance["cat"]) . '">' . apply_filters( 'widget_title', $instance["title"] ) . '</a>';
440
  } else {
441
+ echo apply_filters( 'widget_title', $instance["title"] );
442
  }
443
  echo $after_title;
444
  }
445
 
446
  // Post list
447
  echo "<ul>\n";
448
+
449
+ $current_post_id = null;
450
+ if (is_singular())
451
+ $current_post_id = get_the_ID();
452
+
453
  while ( $cat_posts->have_posts() )
454
  {
455
  $cat_posts->the_post(); ?>
456
 
457
+ <li <?php
458
+ if ( $current_post_id == $cat_posts->post->ID ) {
459
+ echo "class='cat-post-item cat-post-current'";
460
+ } else {
461
+ echo "class='cat-post-item'";
462
+ }
463
+ ?> >
464
 
465
+ <?php
466
+
467
+ // Thumbnail position to top
468
  if( isset( $instance["thumbTop"] ) ) :
469
+ $this->show_thumb();
470
+ endif;
 
 
 
 
 
 
 
471
 
472
+ if( !isset( $instance['hide_post_titles'] ) ) { ?>
473
+ <a class="post-title <?php if( !isset( $instance['disable_css'] ) ) { echo " cat-post-title"; } ?>"
474
+ href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?>
475
+ </a>
476
+ <?php }
477
 
478
+ if ( isset( $instance['date'] ) ) : ?>
479
  <?php if ( isset( $instance['date_format'] ) && strlen( trim( $instance['date_format'] ) ) > 0 ) { $date_format = $instance['date_format']; } else { $date_format = "j M Y"; } ?>
480
  <p class="post-date <?php if( !isset( $instance['disable_css'] ) ) { echo "cat-post-date"; } ?>">
481
  <?php if( isset ( $instance["date_link"] ) ) { ?> <a href="<?php the_permalink(); ?>"><?php } ?>
483
  <?php if( isset ( $instance["date_link"] ) ) { echo "</a>"; } ?>
484
  </p>
485
  <?php endif;
486
+
487
+ // Thumbnail position normal
488
  if( !isset( $instance["thumbTop"] ) ) :
489
+ $this->show_thumb();
 
 
 
 
 
 
 
490
  endif;
491
 
492
  if ( isset( $instance['excerpt'] ) ) :
497
  <p class="comment-num <?php if( !isset( $instance['disable_css'] ) ) { echo "cat-post-comment-num"; } ?>">
498
  (<?php comments_number(); ?>)
499
  </p>
500
+ <?php endif;
501
 
502
  if ( isset( $instance['author'] ) ) : ?>
503
  <p class="post-author <?php if( !isset( $instance['disable_css'] ) ) { echo "cat-post-author"; } ?>">
520
  echo $after_widget;
521
 
522
  remove_filter('excerpt_length', $new_excerpt_length);
523
+ remove_filter('excerpt_more', array($this,'excerpt_more_filter'));
524
+ add_filter('get_the_excerpt', 'wp_trim_excerpt');
525
+ remove_filter('get_the_excerpt', array($this,'allow_html_excerpt'));
526
+
527
  wp_reset_postdata();
528
 
529
  } // END if
552
  'title' => '',
553
  'hide_title' => '',
554
  'cat' => '',
555
+ 'num' => get_option('posts_per_page'),
556
  'sort_by' => '',
557
  'asc_sort_order' => '',
558
  'exclude_current_post' => '',
559
  'title_link' => '',
560
  'footer_link' => '',
561
+ 'hide_post_titles' => '',
562
  'excerpt' => '',
563
+ 'excerpt_length' => 55,
564
+ 'excerpt_allow_html' => '',
565
+ 'excerpt_more_text' => '',
566
  'comment_num' => '',
567
  'author' => '',
568
  'date' => '',
573
  'hideNoThumb' => '',
574
  'thumb_w' => '',
575
  'thumb_h' => '',
576
+ 'use_css_cropping' => '',
577
+ 'thumb_hover' => '',
578
  'disable_css' => '',
579
  'hide_if_empty' => ''
580
  ) );
588
  $exclude_current_post = $instance['exclude_current_post'];
589
  $title_link = $instance['title_link'];
590
  $footer_link = $instance['footer_link'];
591
+ $hide_post_titles = $instance['hide_post_titles'];
592
  $excerpt = $instance['excerpt'];
593
  $excerpt_length = $instance['excerpt_length'];
594
+ $excerpt_allow_html = $instance['excerpt_allow_html'];
595
+ $excerpt_more_text = $instance['excerpt_more_text'];
596
  $comment_num = $instance['comment_num'];
597
  $author = $instance['author'];
598
  $date = $instance['date'];
603
  $hideNoThumb = $instance['hideNoThumb'];
604
  $thumb_w = $instance['thumb_w'];
605
  $thumb_h = $instance['thumb_h'];
606
+ $use_css_cropping = $instance['use_css_cropping'];
607
+ $thumb_hover = $instance['thumb_hover'];
608
  $disable_css = $instance['disable_css'];
609
  $hide_if_empty = $instance['hide_if_empty'];
610
 
611
  ?>
612
  <div class="category-widget-cont">
613
+ <p><a target="_blank" href="http://tiptoppress.com/terms-tags-and-categories-posts-widget/">Get the Pro Version</a></p>
614
+ <p><a target="_blank" href="http://tiptoppress.com/category-posts-widget/documentation/">Documentation</a></p>
615
+ <h4><?php _e('Title','categoryposts')?></h4>
616
+ <div>
617
+ <p>
618
+ <label for="<?php echo $this->get_field_id("title"); ?>">
619
+ <?php _e( 'Title','categoryposts' ); ?>:
620
+ <input class="widefat" style="width:80%;" 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"]); ?>" />
621
+ </label>
622
+ </p>
623
+ <p>
624
+ <label for="<?php echo $this->get_field_id("title_link"); ?>">
625
+ <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 ); ?> />
626
+ <?php _e( 'Make widget title link','categoryposts' ); ?>
627
+ </label>
628
+ </p>
629
+ <p>
630
+ <label for="<?php echo $this->get_field_id("hide_title"); ?>">
631
+ <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 ); ?> />
632
+ <?php _e( 'Hide title','categoryposts' ); ?>
633
+ </label>
634
+ </p>
635
+ </div>
636
+ <h4><?php _e('Filter','categoryposts');?></h4>
637
+ <div>
638
  <p>
639
  <label>
640
  <?php _e( 'Category','categoryposts' ); ?>:
673
  <?php _e( 'Exclude current post','categoryposts' ); ?>
674
  </label>
675
  </p>
676
+ <p>
677
+ <label for="<?php echo $this->get_field_id("hideNoThumb"); ?>">
678
+ <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("hideNoThumb"); ?>" name="<?php echo $this->get_field_name("hideNoThumb"); ?>"<?php checked( (bool) $instance["hideNoThumb"], true ); ?> />
679
+ <?php _e( 'Exclude posts which have no thumbnail','categoryposts' ); ?>
680
+ </label>
681
+ </p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
682
  </div>
683
  <?php if ( current_theme_supports("post-thumbnails") ) : ?>
684
  <h4><?php _e('Thumbnails','categoryposts')?></h4>
689
  <?php _e( 'Show post thumbnail','categoryposts' ); ?>
690
  </label>
691
  </p>
 
 
 
 
 
 
692
  <p>
693
  <label for="<?php echo $this->get_field_id("thumbTop"); ?>">
694
  <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 ); ?> />
695
+ <?php _e( 'Show thumbnails above text','categoryposts' ); ?>
696
  </label>
697
  </p>
698
  <p>
706
  <?php _e('Height:','categoryposts')?> <input class="widefat" style="width:30%;" type="number" min="1" id="<?php echo $this->get_field_id("thumb_h"); ?>" name="<?php echo $this->get_field_name("thumb_h"); ?>" value="<?php echo $instance["thumb_h"]; ?>" />
707
  </label>
708
  </label>
709
+ </p>
710
+ <p>
711
+ <label for="<?php echo $this->get_field_id("use_css_cropping"); ?>">
712
+ <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("use_css_cropping"); ?>" name="<?php echo $this->get_field_name("use_css_cropping"); ?>"<?php checked( (bool) $instance["use_css_cropping"], true ); ?> />
713
+ <?php _e( 'Crop bigger thumbnails around the center ','categoryposts' ); ?>
714
+ </label>
715
+ </p>
716
+ <p>
717
+ <label for="<?php echo $this->get_field_id("thumb_hover"); ?>">
718
+ <?php _e( 'Animation on mouse hover:','categorypostspro' ); ?>
719
+ </label>
720
+ <select id="<?php echo $this->get_field_id("thumb_hover"); ?>" name="<?php echo $this->get_field_name("thumb_hover"); ?>">
721
+ <option value="none" <?php selected($thumb_hover, 'none')?>><?php _e( 'None', 'categorypostspro' ); ?></option>
722
+ <option value="dark" <?php selected($thumb_hover, 'dark')?>><?php _e( 'Darker', 'categorypostspro' ); ?></option>
723
+ <option value="white" <?php selected($thumb_hover, 'white')?>><?php _e( 'Brighter', 'categorypostspro' ); ?></option>
724
+ <option value="scale" <?php selected($thumb_hover, 'scale')?>><?php _e( 'Zoom in', 'categorypostspro' ); ?></option>
725
+ </select>
726
+ </p>
727
  </div>
728
  <?php endif; ?>
729
  <h4><?php _e('Post details','categoryposts')?></h4>
730
  <div>
731
+ <p>
732
+ <label for="<?php echo $this->get_field_id("hide_post_titles"); ?>">
733
+ <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("hide_post_titles"); ?>" name="<?php echo $this->get_field_name("hide_post_titles"); ?>"<?php checked( (bool) $instance["hide_post_titles"], true ); ?> />
734
+ <?php _e( 'Hide post titles','categoryposts' ); ?>
735
+ </label>
736
+ </p>
737
  <p>
738
  <label for="<?php echo $this->get_field_id("excerpt"); ?>">
739
  <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 ); ?> />
744
  <label for="<?php echo $this->get_field_id("excerpt_length"); ?>">
745
  <?php _e( 'Excerpt length (in words):','categoryposts' ); ?>
746
  </label>
747
+ <input style="text-align: center; width:30%;" type="number" min="0" id="<?php echo $this->get_field_id("excerpt_length"); ?>" name="<?php echo $this->get_field_name("excerpt_length"); ?>" value="<?php echo $instance["excerpt_length"]; ?>" />
748
+ </p>
749
+ <p>
750
+ <label for="<?php echo $this->get_field_id("excerpt_allow_html"); ?>">
751
+ <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("excerpt_allow_html"); ?>" name="<?php echo $this->get_field_name("excerpt_allow_html"); ?>"<?php checked( (bool) $instance["excerpt_allow_html"], true ); ?> />
752
+ <?php _e( 'Allow links in excerpt','categoryposts' ); ?>
753
+ </label>
754
+ </p>
755
+ <p>
756
+ <label for="<?php echo $this->get_field_id("excerpt_more_text"); ?>">
757
+ <?php _e( 'Excerpt \'more\' text:','categoryposts' ); ?>
758
+ </label>
759
+ <input class="widefat" style="width:50%;" placeholder="<?php _e('... more','categoryposts')?>" id="<?php echo $this->get_field_id("excerpt_more_text"); ?>" name="<?php echo $this->get_field_name("excerpt_more_text"); ?>" type="text" value="<?php echo $instance["excerpt_more_text"]; ?>" />
760
+ </p>
761
  <p>
762
  <label for="<?php echo $this->get_field_id("date"); ?>">
763
  <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 ); ?> />
789
  </label>
790
  </p>
791
  </div>
792
+ <h4><?php _e('General','categoryposts')?></h4>
 
 
 
 
 
 
 
 
 
793
  <div>
794
  <p>
795
  <label for="<?php echo $this->get_field_id("disable_css"); ?>">
796
  <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 ); ?> />
797
+ <?php _e( 'Disable the built-in CSS for this widget','categoryposts' ); ?>
798
  </label>
799
  </p>
800
  <p>
801
  <label for="<?php echo $this->get_field_id("hide_if_empty"); ?>">
802
  <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 ); ?> />
803
+ <?php _e( 'Hide widget if there are no matching posts','categoryposts' ); ?>
804
  </label>
805
  </p>
806
  </div>
807
+ <h4><?php _e('Footer','categoryposts')?></h4>
808
+ <div>
809
+ <p>
810
+ <label for="<?php echo $this->get_field_id("footer_link"); ?>">
811
+ <?php _e( 'Footer link text','categoryposts' ); ?>:
812
+ <input class="widefat" style="width:60%;" placeholder="<?php _e('... more by this topic','categoryposts')?>" id="<?php echo $this->get_field_id("footer_link"); ?>" name="<?php echo $this->get_field_name("footer_link"); ?>" type="text" value="<?php echo esc_attr($instance["footer_link"]); ?>" />
813
+ </label>
814
+ </p>
815
+ </div>
816
+ <h4>Follow us on</h4>
817
+ <div>
818
+ <a target="_blank" href="https://www.facebook.com/TipTopPress">Facebook</a> and
819
+ <a target="_blank" href="https://twitter.com/TipTopPress">Twitter</a></br></br>
820
+ </br>
821
+ </div>
822
  </div>
823
  <?php
824
  }
825
  }
826
 
827
+ function category_posts_register_widget() {
828
+ return register_widget("CategoryPosts");
829
+ }
830
+
831
+ add_action( 'widgets_init', 'category_posts_register_widget' );
js/admin/category-posts-widget.js CHANGED
@@ -11,14 +11,14 @@ if (window.jQuery) {
11
 
12
  jQuery('.category-widget-cont h4').click(function () { // for widgets page
13
  jQuery(this).toggleClass('open')
14
- .next().slideToggle('open');
15
  })
16
 
17
 
18
  jQuery(document).on('widget-added widget-updated', function(){ // for customize and after save on widgets page
19
- jQuery('.category-widget-cont h4').click(function () {
20
  jQuery(this).toggleClass('open')
21
- .next().slideToggle('open');
22
  })
23
  });
24
- }
11
 
12
  jQuery('.category-widget-cont h4').click(function () { // for widgets page
13
  jQuery(this).toggleClass('open')
14
+ .next().stop().slideToggle('open');
15
  })
16
 
17
 
18
  jQuery(document).on('widget-added widget-updated', function(){ // for customize and after save on widgets page
19
+ jQuery('.category-widget-cont h4').off('click').on('click', function () {
20
  jQuery(this).toggleClass('open')
21
+ .next().stop().slideToggle('open');
22
  })
23
  });
24
+ }
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: mkrdip, mark-k, 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.4.1
7
- Stable tag: 4.1.5
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -24,6 +24,8 @@ We giving you a 50%-special discount code: **'WordPress'**. (Enter it after chec
24
  = Features =
25
  * Option to change ordering of posts.
26
  * Option to show post thumbnail & set dimension by width & height.
 
 
27
  * Option to put thumbnail on top
28
  * Option to hide posts which have no thumbnail.
29
  * Option to disable widget CSS.
@@ -31,19 +33,18 @@ We giving you a 50%-special discount code: **'WordPress'**. (Enter it after chec
31
  * Option exclude current post.
32
  * Option show post author.
33
  * Set which category the posts should come form.
34
- * Option to show the post excerpt and how long the excerpt should be.
35
  * Option to show the post date.
36
  * Option to make the widget date link to the category page.
37
  * Option to format the outputted date string.
38
  * Option to show the comment count.
39
  * Option to make the widget title link to the category page.
40
  * Option to link to the category page below posts list.
41
- * Option to hide the title.
42
  * Option to hide widget, if category have currently no posts.
43
  * Multiple widgets.
44
  * Multi sites support.
45
  * Localization support.
46
- * Generate thumbs from existing images.
47
 
48
  = Documentation =
49
  Formatting date and time: See <a target="_blank" href="https://codex.wordpress.org/Formatting_Date_and_Time">Formatting Date and Time</a>.
@@ -74,7 +75,7 @@ Automatic installation is the easiest option as WordPress handles the file trans
74
  * Version 3.0 or later version uses WordPress 2.9's built in post thumbnail functionality.
75
 
76
  == Frequently Asked Questions ==
77
- = The font-size is different from that of other widgets? =
78
  Please use the option: "Disable widget CSS".
79
 
80
  = I want the title as a link pointing to the selected Categorie page? =
@@ -85,7 +86,15 @@ Enable the check box "Make widget title link".
85
  2. Front end of the widget using a default WordPress Theme.
86
 
87
  == Changelog ==
88
- = 4.1.5 - February 4 2016 =
 
 
 
 
 
 
 
 
89
  * Support for multi sites.
90
  * Support for localization.
91
  * Generate thumbs from existing images.
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.5
7
+ Stable tag: 4.1.6
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
24
  = Features =
25
  * Option to change ordering of posts.
26
  * Option to show post thumbnail & set dimension by width & height.
27
+ * Option to crop thumbnails with CSS. <a target="_blank" href="http://tiptoppress.com/css-image-crop/">What is 'CSS Image Crop'?</a>
28
+ * Option to set mouse hover effects for post thumbnail.
29
  * Option to put thumbnail on top
30
  * Option to hide posts which have no thumbnail.
31
  * Option to disable widget CSS.
33
  * Option exclude current post.
34
  * Option show post author.
35
  * Set which category the posts should come form.
36
+ * Option to show the post excerpt, set the length, allow links and change 'more' text.
37
  * Option to show the post date.
38
  * Option to make the widget date link to the category page.
39
  * Option to format the outputted date string.
40
  * Option to show the comment count.
41
  * Option to make the widget title link to the category page.
42
  * Option to link to the category page below posts list.
43
+ * Option to hide the widget title and post titles.
44
  * Option to hide widget, if category have currently no posts.
45
  * Multiple widgets.
46
  * Multi sites support.
47
  * Localization support.
 
48
 
49
  = Documentation =
50
  Formatting date and time: See <a target="_blank" href="https://codex.wordpress.org/Formatting_Date_and_Time">Formatting Date and Time</a>.
75
  * Version 3.0 or later version uses WordPress 2.9's built in post thumbnail functionality.
76
 
77
  == Frequently Asked Questions ==
78
+ = The font-size is different from that of other widgets or Theme elements? =
79
  Please use the option: "Disable widget CSS".
80
 
81
  = I want the title as a link pointing to the selected Categorie page? =
86
  2. Front end of the widget using a default WordPress Theme.
87
 
88
  == Changelog ==
89
+ = 4.1.6 - April 13th 2016 =
90
+ * Add option CSS cropping for thumbnails.
91
+ * Add option to set mouse hover effects for post thumbnail.
92
+ * Add option to change the excerpt more text.
93
+ * Add option to allow links in the excerpt
94
+ * Add filter 'widget_title' for the title
95
+ * Add option to hide post titles.
96
+
97
+ = 4.1.5 - February 4th 2016 =
98
  * Support for multi sites.
99
  * Support for localization.
100
  * Generate thumbs from existing images.