WP Tab Widget - Version 1.2

Version Description

  • Added Title Length option
  • Fixed post view count compatibility with themes
Download this release

Release Info

Developer MyThemeShop
Plugin Icon 128x128 WP Tab Widget
Version 1.2
Comparing to
See all releases

Code changes from version 1.1 to 1.2

Files changed (2) hide show
  1. readme.txt +6 -2
  2. wp-tab-widget.php +59 -23
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: mythemeshop
3
  Creator's website link: http://mythemeshop.com/
4
  Tags: tabs, tab widget, recent posts tab, tabs widget, ajax tabs, ajax widget.
5
  Requires at least: 3.0.1
6
- Tested up to: 4.0
7
- Stable tag: 1.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -75,6 +75,10 @@ Please disable all plugins and check if shortcode plugin is working properly. Th
75
 
76
  == Changelog ==
77
 
 
 
 
 
78
  = 1.1 =
79
  * Popular posts will be decided by number of views.
80
  * Added loading effect.
3
  Creator's website link: http://mythemeshop.com/
4
  Tags: tabs, tab widget, recent posts tab, tabs widget, ajax tabs, ajax widget.
5
  Requires at least: 3.0.1
6
+ Tested up to: 4.2
7
+ Stable tag: 1.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
75
 
76
  == Changelog ==
77
 
78
+ = 1.2 =
79
+ * Added Title Length option
80
+ * Fixed post view count compatibility with themes
81
+
82
  = 1.1 =
83
  * Popular posts will be decided by number of views.
84
  * Added loading effect.
wp-tab-widget.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: WP Tab Widget
4
  Plugin URI: http://mythemeshop.com/plugins/wp-tab-widget/
5
  Description: WP Tab Widget is the AJAXified plugin which loads content by demand, and thus it makes the plugin incredibly lightweight.
6
  Author: MyThemeShop
7
- Version: 1.1
8
  Author URI: http://mythemeshop.com/
9
  */
10
 
@@ -50,8 +50,24 @@ class wpt_widget extends WP_Widget {
50
  }
51
 
52
  function form( $instance ) {
53
- $instance = wp_parse_args( (array) $instance, array( 'tabs' => array('recent' => 1, 'popular' => 1, 'comments' => 0, 'tags' => 0), 'tab_order' => array('popular' => 1, 'recent' => 2, 'comments' => 3, 'tags' => 4), 'allow_pagination' => 1, 'post_num' => '5', 'comment_num' => '5', 'show_thumb' => 1, 'thumb_size' => 'small', 'show_date' => 1, 'show_excerpt' => 0, 'excerpt_length' => 10, 'show_comment_num' => 0, 'show_avatar' => 1) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  extract($instance);
 
55
  ?>
56
  <div class="wpt_options_form">
57
 
@@ -118,6 +134,13 @@ class wpt_widget extends WP_Widget {
118
  <input id="<?php echo $this->get_field_id('post_num'); ?>" name="<?php echo $this->get_field_name('post_num'); ?>" type="number" min="1" step="1" value="<?php echo $post_num; ?>" />
119
  </label>
120
  </p>
 
 
 
 
 
 
 
121
 
122
  <p>
123
  <label for="<?php echo $this->get_field_id("show_thumb"); ?>">
@@ -194,6 +217,7 @@ class wpt_widget extends WP_Widget {
194
  $instance['tab_order'] = $new_instance['tab_order'];
195
  $instance['allow_pagination'] = $new_instance['allow_pagination'];
196
  $instance['post_num'] = $new_instance['post_num'];
 
197
  $instance['comment_num'] = $new_instance['comment_num'];
198
  $instance['show_thumb'] = $new_instance['show_thumb'];
199
  $instance['thumb_size'] = $new_instance['thumb_size'];
@@ -307,7 +331,9 @@ class wpt_widget extends WP_Widget {
307
  }
308
  $show_comment_num = !empty($args['show_comment_num']);
309
  $show_avatar = !empty($args['show_avatar']);
310
- $allow_pagination = !empty($args['allow_pagination']);
 
 
311
 
312
  /* ---------- Tab Contents ---------- */
313
  switch ($tab) {
@@ -332,7 +358,7 @@ class wpt_widget extends WP_Widget {
332
  </a>
333
  </div>
334
  <?php endif; ?>
335
- <div class="entry-title"><a title="<?php the_title(); ?>" href="<?php the_permalink() ?>"><?php echo get_the_title(); ?></a></div>
336
  <?php if ( $show_date == 1 || $show_comment_num == 1) : ?>
337
  <div class="wpt-postmeta">
338
  <?php if ( $show_date == 1 ) : ?>
@@ -385,7 +411,7 @@ class wpt_widget extends WP_Widget {
385
  </a>
386
  </div>
387
  <?php endif; ?>
388
- <div class="entry-title"><a title="<?php the_title(); ?>" href="<?php the_permalink() ?>"><?php echo get_the_title(); ?></a></div>
389
  <?php if ( $show_date == 1 || $show_comment_num == 1) : ?>
390
  <div class="wpt-postmeta">
391
  <?php if ( $show_date == 1 ) : ?>
@@ -432,24 +458,22 @@ class wpt_widget extends WP_Widget {
432
  $offset = ($page-1) * $comment_num;
433
  $comments = $comments_query->query( array( 'number' => $comment_num, 'offset' => $offset, 'status' => 'approve' ) );
434
  if ( $comments ) : foreach ( $comments as $comment ) : ?>
435
- <li>
436
-
437
- <?php if ($show_avatar) : ?>
438
- <div class="wpt_avatar">
439
- <a href="<?php echo get_comment_link($comment->comment_ID); ?>">
440
- <?php echo get_avatar( $comment->comment_author_email, $avatar_size ); ?>
441
- </a>
442
- </div>
443
- <?php endif; ?>
444
- <div class="wpt_comment_meta">
445
- <a href="<?php echo get_comment_link($comment->comment_ID); ?>">
446
- <span class="wpt_comment_author"><?php echo get_comment_author( $comment->comment_ID ); ?> </span> - <span class="wpt_comment_post"><?php echo get_the_title($comment->comment_post_ID); ?></span>
447
- </a>
448
- </div>
449
- <div class="wpt_comment_content">
450
- <p><?php echo $this->truncate(strip_tags(apply_filters( 'get_comment_text', $comment->comment_content )), $comment_length);?></p>
451
  </div>
452
- </a>
 
 
 
 
 
 
 
 
453
  <div class="clear"></div>
454
  </li>
455
  <?php endforeach; else : ?>
@@ -502,6 +526,7 @@ class wpt_widget extends WP_Widget {
502
  }
503
 
504
  function excerpt($limit = 10) {
 
505
  $excerpt = explode(' ', get_the_excerpt(), $limit);
506
  if (count($excerpt)>=$limit) {
507
  array_pop($excerpt);
@@ -512,6 +537,17 @@ class wpt_widget extends WP_Widget {
512
  $excerpt = preg_replace('`[[^]]*]`','',$excerpt);
513
  return $excerpt;
514
  }
 
 
 
 
 
 
 
 
 
 
 
515
  function truncate($str, $length = 24) {
516
  if (mb_strlen($str) > $length) {
517
  return mb_substr($str, 0, $length).'...';
@@ -529,7 +565,7 @@ add_filter('the_content', 'wpt_view_count_js'); // outputs JS for AJAX call on s
529
  add_action('wp_ajax_wpt_view_count', 'ajax_wpt_view_count');
530
  add_action('wp_ajax_nopriv_wpt_view_count','ajax_wpt_view_count');
531
  // prevent additional ajax call if theme has view counter already
532
- add_action('mts_view_count_after_update', 'wpt_add_view_count');
533
 
534
  function wpt_view_count_js( $content ) {
535
  global $post;
4
  Plugin URI: http://mythemeshop.com/plugins/wp-tab-widget/
5
  Description: WP Tab Widget is the AJAXified plugin which loads content by demand, and thus it makes the plugin incredibly lightweight.
6
  Author: MyThemeShop
7
+ Version: 1.2
8
  Author URI: http://mythemeshop.com/
9
  */
10
 
50
  }
51
 
52
  function form( $instance ) {
53
+ $instance = wp_parse_args( (array) $instance, array(
54
+ 'tabs' => array('recent' => 1, 'popular' => 1, 'comments' => 0, 'tags' => 0),
55
+ 'tab_order' => array('popular' => 1, 'recent' => 2, 'comments' => 3, 'tags' => 4),
56
+ 'allow_pagination' => 1,
57
+ 'post_num' => '5',
58
+ 'comment_num' => '5',
59
+ 'show_thumb' => 1,
60
+ 'thumb_size' => 'small',
61
+ 'show_date' => 1,
62
+ 'show_excerpt' => 0,
63
+ 'excerpt_length' => apply_filters( 'wpt_excerpt_length_default', '15' ),
64
+ 'show_comment_num' => 0,
65
+ 'show_avatar' => 1,
66
+ 'title_length' => apply_filters( 'wpt_title_length_default', '15' )
67
+ ) );
68
+
69
  extract($instance);
70
+
71
  ?>
72
  <div class="wpt_options_form">
73
 
134
  <input id="<?php echo $this->get_field_id('post_num'); ?>" name="<?php echo $this->get_field_name('post_num'); ?>" type="number" min="1" step="1" value="<?php echo $post_num; ?>" />
135
  </label>
136
  </p>
137
+
138
+ <p>
139
+ <label for="<?php echo $this->get_field_id('title_length'); ?>"><?php _e('Title length (words):', 'mts_wpt'); ?>
140
+ <br />
141
+ <input id="<?php echo $this->get_field_id('title_length'); ?>" name="<?php echo $this->get_field_name('title_length'); ?>" type="number" min="1" step="1" value="<?php echo $title_length; ?>" />
142
+ </label>
143
+ </p>
144
 
145
  <p>
146
  <label for="<?php echo $this->get_field_id("show_thumb"); ?>">
217
  $instance['tab_order'] = $new_instance['tab_order'];
218
  $instance['allow_pagination'] = $new_instance['allow_pagination'];
219
  $instance['post_num'] = $new_instance['post_num'];
220
+ $instance['title_length'] = $new_instance['title_length'];
221
  $instance['comment_num'] = $new_instance['comment_num'];
222
  $instance['show_thumb'] = $new_instance['show_thumb'];
223
  $instance['thumb_size'] = $new_instance['thumb_size'];
331
  }
332
  $show_comment_num = !empty($args['show_comment_num']);
333
  $show_avatar = !empty($args['show_avatar']);
334
+ $allow_pagination = !empty($args['allow_pagination']);
335
+
336
+ $title_length = ! empty($args['title_length']) ? $args['title_length'] : apply_filters( 'wpt_title_length_default', '15' );
337
 
338
  /* ---------- Tab Contents ---------- */
339
  switch ($tab) {
358
  </a>
359
  </div>
360
  <?php endif; ?>
361
+ <div class="entry-title"><a title="<?php the_title(); ?>" href="<?php the_permalink() ?>"><?php echo $this->post_title( $title_length ); ?></a></div>
362
  <?php if ( $show_date == 1 || $show_comment_num == 1) : ?>
363
  <div class="wpt-postmeta">
364
  <?php if ( $show_date == 1 ) : ?>
411
  </a>
412
  </div>
413
  <?php endif; ?>
414
+ <div class="entry-title"><a title="<?php the_title(); ?>" href="<?php the_permalink() ?>"><?php echo $this->post_title( $title_length ); ?></a></div>
415
  <?php if ( $show_date == 1 || $show_comment_num == 1) : ?>
416
  <div class="wpt-postmeta">
417
  <?php if ( $show_date == 1 ) : ?>
458
  $offset = ($page-1) * $comment_num;
459
  $comments = $comments_query->query( array( 'number' => $comment_num, 'offset' => $offset, 'status' => 'approve' ) );
460
  if ( $comments ) : foreach ( $comments as $comment ) : ?>
461
+ <li>
462
+ <?php if ($show_avatar) : ?>
463
+ <div class="wpt_avatar">
464
+ <a href="<?php echo get_comment_link($comment->comment_ID); ?>">
465
+ <?php echo get_avatar( $comment->comment_author_email, $avatar_size ); ?>
466
+ </a>
 
 
 
 
 
 
 
 
 
 
467
  </div>
468
+ <?php endif; ?>
469
+ <div class="wpt_comment_meta">
470
+ <a href="<?php echo get_comment_link($comment->comment_ID); ?>">
471
+ <span class="wpt_comment_author"><?php echo get_comment_author( $comment->comment_ID ); ?> </span> - <span class="wpt_comment_post"><?php echo get_the_title($comment->comment_post_ID); ?></span>
472
+ </a>
473
+ </div>
474
+ <div class="wpt_comment_content">
475
+ <p><?php echo $this->truncate(strip_tags(apply_filters( 'get_comment_text', $comment->comment_content )), $comment_length);?></p>
476
+ </div>
477
  <div class="clear"></div>
478
  </li>
479
  <?php endforeach; else : ?>
526
  }
527
 
528
  function excerpt($limit = 10) {
529
+ $limit++;
530
  $excerpt = explode(' ', get_the_excerpt(), $limit);
531
  if (count($excerpt)>=$limit) {
532
  array_pop($excerpt);
537
  $excerpt = preg_replace('`[[^]]*]`','',$excerpt);
538
  return $excerpt;
539
  }
540
+ function post_title($limit = 10) {
541
+ $limit++;
542
+ $title = explode(' ', get_the_title(), $limit);
543
+ if (count($title)>=$limit) {
544
+ array_pop($title);
545
+ $title = implode(" ",$title).'...';
546
+ } else {
547
+ $title = implode(" ",$title);
548
+ }
549
+ return $title;
550
+ }
551
  function truncate($str, $length = 24) {
552
  if (mb_strlen($str) > $length) {
553
  return mb_substr($str, 0, $length).'...';
565
  add_action('wp_ajax_wpt_view_count', 'ajax_wpt_view_count');
566
  add_action('wp_ajax_nopriv_wpt_view_count','ajax_wpt_view_count');
567
  // prevent additional ajax call if theme has view counter already
568
+ add_action('mts_view_count_after_update', 'wpt_update_view_count');
569
 
570
  function wpt_view_count_js( $content ) {
571
  global $post;