List category posts - Version 0.74

Version Description

  • Adds "next" and "previous" classes to the previous and next buttons in pagination menu. The classes are lcp_prevlink and lcp_nextlink. Thanks @zymeth25.
  • Adds pagination to Widget.
Download this release

Release Info

Developer fernandobt
Plugin Icon 128x128 List category posts
Version 0.74
Comparing to
See all releases

Code changes from version 0.73.2 to 0.74

include/lcp-category.php CHANGED
@@ -8,12 +8,12 @@ class LcpCategory{
8
  // Singleton implementation
9
  private static $instance = null;
10
 
11
- public static function get_instance(){
12
- if( !isset( self::$instance ) ){
13
- self::$instance = new self;
14
- }
15
- return self::$instance;
16
- }
17
 
18
  /*
19
  * When the category is set using the `name` parameter.
8
  // Singleton implementation
9
  private static $instance = null;
10
 
11
+ public static function get_instance(){
12
+ if( !isset( self::$instance ) ){
13
+ self::$instance = new self;
14
+ }
15
+ return self::$instance;
16
+ }
17
 
18
  /*
19
  * When the category is set using the `name` parameter.
include/lcp-catlist.php CHANGED
@@ -4,6 +4,7 @@ require_once ( LCP_PATH . 'lcp-thumbnail.php' );
4
  require_once ( LCP_PATH . 'lcp-parameters.php' );
5
  require_once ( LCP_PATH . 'lcp-utils.php' );
6
  require_once ( LCP_PATH . 'lcp-category.php' );
 
7
 
8
  /**
9
  * The CatList object gets the info for the CatListDisplayer to show.
@@ -422,4 +423,16 @@ class CatList{
422
  $lcp_thumb_class);
423
  }
424
 
 
 
 
 
 
 
 
 
 
 
 
 
425
  }
4
  require_once ( LCP_PATH . 'lcp-parameters.php' );
5
  require_once ( LCP_PATH . 'lcp-utils.php' );
6
  require_once ( LCP_PATH . 'lcp-category.php' );
7
+ require_once ( LCP_PATH . 'lcp-paginator.php' );
8
 
9
  /**
10
  * The CatList object gets the info for the CatListDisplayer to show.
423
  $lcp_thumb_class);
424
  }
425
 
426
+ public function get_pagination(){
427
+ $paginator_params = array(
428
+ 'instance' => $this->get_instance(),
429
+ 'next' => $this->params['pagination_next'],
430
+ 'numberposts' => $this->get_number_posts(),
431
+ 'page' => $this->get_page(),
432
+ 'pagination' => $this->params['pagination'],
433
+ 'posts_count' => $this->get_posts_count(),
434
+ 'previous' => $this->params['pagination_prev']
435
+ );
436
+ return LcpPaginator::get_instance()->get_pagination($paginator_params);
437
+ }
438
  }
include/lcp-catlistdisplayer.php CHANGED
@@ -151,81 +151,7 @@ class CatListDisplayer {
151
  // More link
152
  $this->lcp_output .= $this->get_morelink();
153
 
154
- $this->lcp_output .= $this->get_pagination();
155
- }
156
-
157
- public function get_pagination(){
158
- $pag_output = '';
159
- $lcp_pag_present = !empty($this->params['pagination']);
160
- if ($lcp_pag_present && $this->params['pagination'] == "yes" ||
161
- # Check if the pagination option is set to true, and the param
162
- # is not set to 'no' (since shortcode parameters should
163
- # override general options.
164
- (get_option('lcp_pagination') === 'true' && ($lcp_pag_present && $this->params['pagination'] !== 'false'))):
165
- $lcp_paginator = '';
166
- $number_posts = $this->catlist->get_number_posts();
167
- $pages_count = ceil (
168
- $this->catlist->get_posts_count() /
169
- # Avoid dividing by 0 (pointed out by @rhj4)
170
- max( array( 1, $number_posts ) )
171
- );
172
- if ($pages_count > 1){
173
- for($i = 1; $i <= $pages_count; $i++){
174
- $lcp_paginator .= $this->lcp_page_link($i);
175
- }
176
-
177
- $pag_output .= "<ul class='lcp_paginator'>";
178
-
179
- // Add "Previous" link
180
- if ($this->catlist->get_page() > 1){
181
- $pag_output .= $this->lcp_page_link( intval($this->catlist->get_page()) - 1, $this->params['pagination_prev'] );
182
- }
183
-
184
- $pag_output .= $lcp_paginator;
185
-
186
- // Add "Next" link
187
- if ($this->catlist->get_page() < $pages_count){
188
- $pag_output .= $this->lcp_page_link( intval($this->catlist->get_page()) + 1, $this->params['pagination_next']);
189
- }
190
-
191
- $pag_output .= "</ul>";
192
- }
193
- endif;
194
- return $pag_output;
195
- }
196
-
197
- private function lcp_page_link($page, $char = null){
198
- $current_page = $this->catlist->get_page();
199
- $link = '';
200
-
201
- if ($page == $current_page){
202
- $link = "<li class='lcp_currentpage'>$current_page</li>";
203
- } else {
204
- $server_vars = add_magic_quotes($_SERVER);
205
- $request_uri = $server_vars['REQUEST_URI'];
206
- $query = $server_vars['QUERY_STRING'];
207
- $amp = ( strpos( $request_uri, "?") ) ? "&" : "";
208
- $pattern = "/[&|?]?lcp_page" . preg_quote($this->catlist->get_instance()) . "=([0-9]+)/";
209
- $query = preg_replace($pattern, '', $query);
210
-
211
- $url = strtok($request_uri,'?');
212
- $protocol = "http";
213
- $port = $server_vars['SERVER_PORT'];
214
- if ( (!empty($server_vars['HTTPS']) && $server_vars['HTTPS'] !== 'off') || $port == 443){
215
- $protocol = "https";
216
- }
217
- $http_host = $server_vars['HTTP_HOST'];
218
- $page_link = "$protocol://$http_host$url?$query" .
219
- $amp . "lcp_page" . $this->catlist->get_instance() . "=". $page .
220
- "#lcp_instance_" . $this->catlist->get_instance();
221
- $link .= "<li><a href='$page_link' title='$page'>";
222
- ($char != null) ? ($link .= $char) : ($link .= $page);
223
-
224
- $link .= "</a></li>";
225
- }
226
- // WA: Replace '?&' by '?' to avoid potential redirection problems later on
227
- $link = str_replace('?&', '?', $link );
228
- return $link;
229
  }
230
 
231
  /**
151
  // More link
152
  $this->lcp_output .= $this->get_morelink();
153
 
154
+ $this->lcp_output .= $this->catlist->get_pagination();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155
  }
156
 
157
  /**
include/lcp-paginator.php ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?
2
+ /**
3
+ * Class to build pagination
4
+ * @author fernando@picandocodigo.net
5
+ */
6
+
7
+ class LcpPaginator {
8
+ private $catlist;
9
+ private $prev_page_num;
10
+ private $next_page_num;
11
+
12
+ // Singleton implementation
13
+ private static $instance = null;
14
+ public static function get_instance(){
15
+ if( !isset( self::$instance ) ){
16
+ self::$instance = new self;
17
+ }
18
+ return self::$instance;
19
+ }
20
+
21
+ # Define if pagination should be displayed based on 'pagination' param and option.
22
+ # Check if the pagination option is set to true, and the param
23
+ # is not set to 'no' (since shortcode parameters should
24
+ # override general options).
25
+ # Receives params['pagination'] from CatList
26
+ private function show_pagination($pagination){
27
+ return !empty($pagination) &&
28
+ $pagination == 'yes' ||
29
+ (get_option('lcp_pagination') === 'true' &&
30
+ ($lcp_pag_present &&
31
+ $pagination !== 'false')
32
+ );
33
+ }
34
+
35
+ public function get_pagination($params){
36
+ if ($this->show_pagination($params['pagination'])){
37
+ $lcp_paginator = '';
38
+ $pages_count = ceil (
39
+ $params['posts_count'] /
40
+ # Avoid dividing by 0 (pointed out by @rhj4)
41
+ max( array( 1, $params['numberposts'] ) )
42
+ );
43
+ $pag_output = '';
44
+ if ($pages_count > 1){
45
+ for($i = 1; $i <= $pages_count; $i++){
46
+ $lcp_paginator .= $this->lcp_page_link($i, $params['page'], $params['instance']);
47
+ }
48
+
49
+ $pag_output .= "<ul class='lcp_paginator'>";
50
+
51
+ // Add "Previous" link
52
+ if ($params['page'] > 1){
53
+ $this->prev_page_num = intval(intval($params['page']) - 1);
54
+ $pag_output .= $this->lcp_page_link($this->prev_page_num , $params['page'], $params['instance'], $params['previous'] );
55
+ }
56
+
57
+ $pag_output .= $lcp_paginator;
58
+
59
+ // Add "Next" link
60
+ if ($params['page'] < $pages_count){
61
+ $this->next_page_num = intval($params['page'] + 1);
62
+ $pag_output .= $this->lcp_page_link($this->next_page_num, $params['page'], $params['instance'], $params['next']);
63
+ }
64
+
65
+ $pag_output .= "</ul>";
66
+ }
67
+ return $pag_output;
68
+ }
69
+ }
70
+
71
+
72
+ // `char` is the string from pagination_prev/pagination_next
73
+ private function lcp_page_link($page, $current_page, $lcp_instance, $char = null){
74
+ $link = '';
75
+
76
+ if ($page == $current_page){
77
+ $link = "<li class='lcp_currentpage'>$current_page</li>";
78
+ } else {
79
+ $server_vars = add_magic_quotes($_SERVER);
80
+ $request_uri = $server_vars['REQUEST_URI'];
81
+ $query = $server_vars['QUERY_STRING'];
82
+ $amp = ( strpos( $request_uri, "?") ) ? "&" : "";
83
+ $pattern = "/[&|?]?lcp_page" . preg_quote($lcp_instance) . "=([0-9]+)/";
84
+ $query = preg_replace($pattern, '', $query);
85
+
86
+ $url = strtok($request_uri,'?');
87
+ $protocol = "http";
88
+ $port = $server_vars['SERVER_PORT'];
89
+ if ( (!empty($server_vars['HTTPS']) && $server_vars['HTTPS'] !== 'off') || $port == 443){
90
+ $protocol = "https";
91
+ }
92
+ $http_host = $server_vars['HTTP_HOST'];
93
+ $page_link = "$protocol://$http_host$url?$query" .
94
+ $amp . "lcp_page" . $lcp_instance . "=". $page .
95
+ "#lcp_instance_" . $lcp_instance;
96
+ $link .= "<li><a href='$page_link' title='$page'";
97
+ if ($page === $this->prev_page_num) {
98
+ $link .= "class='lcp_prevlink'";
99
+ } elseif ($page === $this->next_page_num) {
100
+ $link .= "class='lcp_nextlink'";
101
+ }
102
+ $link .= ">";
103
+ ($char != null) ? ($link .= $char) : ($link .= $page);
104
+
105
+ $link .= "</a></li>";
106
+ }
107
+ // WA: Replace '?&' by '?' to avoid potential redirection problems later on
108
+ $link = str_replace('?&', '?', $link );
109
+ return $link;
110
+ }
111
+ }
include/lcp-parameters.php CHANGED
@@ -10,12 +10,12 @@ class LcpParameters{
10
  private $utils;
11
  private $params;
12
 
13
- public static function get_instance(){
14
- if( !isset( self::$instance ) ){
15
- self::$instance = new self;
16
- }
17
- return self::$instance;
18
- }
19
 
20
  public function get_query_params($params){
21
  $this->params = $params;
10
  private $utils;
11
  private $params;
12
 
13
+ public static function get_instance(){
14
+ if( !isset( self::$instance ) ){
15
+ self::$instance = new self;
16
+ }
17
+ return self::$instance;
18
+ }
19
 
20
  public function get_query_params($params){
21
  $this->params = $params;
include/lcp-thumbnail.php CHANGED
@@ -3,12 +3,12 @@ class LcpThumbnail{
3
  // Singleton implementation
4
  private static $instance = null;
5
 
6
- public static function get_instance(){
7
- if( !isset( self::$instance ) ){
8
- self::$instance = new self;
9
- }
10
- return self::$instance;
11
- }
12
 
13
  /**
14
  * Get the post Thumbnail
3
  // Singleton implementation
4
  private static $instance = null;
5
 
6
+ public static function get_instance(){
7
+ if( !isset( self::$instance ) ){
8
+ self::$instance = new self;
9
+ }
10
+ return self::$instance;
11
+ }
12
 
13
  /**
14
  * Get the post Thumbnail
include/lcp-widget-form.php CHANGED
@@ -23,6 +23,7 @@
23
  'morelink' =>'',
24
  'tags_as_class' => '',
25
  'template' => '',
 
26
  );
27
  $instance = wp_parse_args( (array) $instance, $default);
28
 
@@ -45,6 +46,7 @@
45
  $morelink = strip_tags($instance['morelink']);
46
  $tags_as_class = strip_tags($instance['tags_as_class']);
47
  $template = strip_tags($instance['template']);
 
48
 
49
  ?>
50
 
@@ -100,9 +102,9 @@
100
  <p>
101
  <label for="<?php echo $this->get_field_id('offset'); ?>">
102
  <?php _e("Offset", 'list-category-posts')?>: <br/>
103
- <input size="2" id="<?php echo $this->get_field_id('offset'); ?>"
104
- name="<?php echo $this->get_field_name('offset'); ?>" type="text"
105
- value="<?php echo esc_attr($offset); ?>" />
106
  </label>
107
  </p>
108
 
@@ -175,19 +177,27 @@
175
  <select id="<?php echo $this->get_field_id('thumbnail_size'); ?>"
176
  name="<?php echo $this->get_field_name( 'thumbnail_size' ); ?>" type="text">
177
  <?php foreach($image_sizes as $image_size) { ?>
178
- <option value='<?php echo $image_size ?>' <?php
179
- if($thumbnail_size == $image_size) echo 'selected';
180
- ?>><?php echo $image_size ?></option>
181
  <?php } ?>
182
  </select>
183
  </p>
184
 
 
 
 
 
 
 
 
185
  <p>
186
  <input class="checkbox" type="checkbox"
187
  <?php checked( (bool) $instance['show_date'], true ); ?>
188
  name="<?php echo $this->get_field_name( 'show_date' ); ?>" />
189
  <?php _e("Date", 'list-category-posts')?>
190
  </p>
 
191
  <p>
192
  <input class="checkbox" type="checkbox"
193
  <?php checked( (bool) $instance['show_modified_date'], true ); ?>
23
  'morelink' =>'',
24
  'tags_as_class' => '',
25
  'template' => '',
26
+ 'pagination' => ''
27
  );
28
  $instance = wp_parse_args( (array) $instance, $default);
29
 
46
  $morelink = strip_tags($instance['morelink']);
47
  $tags_as_class = strip_tags($instance['tags_as_class']);
48
  $template = strip_tags($instance['template']);
49
+ $pagination = strip_tags($instance['pagination']);
50
 
51
  ?>
52
 
102
  <p>
103
  <label for="<?php echo $this->get_field_id('offset'); ?>">
104
  <?php _e("Offset", 'list-category-posts')?>: <br/>
105
+ <input size="2" id="<?php echo $this->get_field_id('offset'); ?>"
106
+ name="<?php echo $this->get_field_name('offset'); ?>" type="text"
107
+ value="<?php echo esc_attr($offset); ?>" />
108
  </label>
109
  </p>
110
 
177
  <select id="<?php echo $this->get_field_id('thumbnail_size'); ?>"
178
  name="<?php echo $this->get_field_name( 'thumbnail_size' ); ?>" type="text">
179
  <?php foreach($image_sizes as $image_size) { ?>
180
+ <option value='<?php echo $image_size ?>' <?php
181
+ if($thumbnail_size == $image_size) echo 'selected';
182
+ ?>><?php echo $image_size ?></option>
183
  <?php } ?>
184
  </select>
185
  </p>
186
 
187
+ <p>
188
+ <input class="checkbox" type="checkbox"
189
+ <?php checked( (bool) $instance['pagination'], true ); ?>
190
+ name="<?php echo $this->get_field_name( 'pagination' ); ?>" />
191
+ <?php _e("Pagination", 'list-category-posts')?>
192
+ </p>
193
+
194
  <p>
195
  <input class="checkbox" type="checkbox"
196
  <?php checked( (bool) $instance['show_date'], true ); ?>
197
  name="<?php echo $this->get_field_name( 'show_date' ); ?>" />
198
  <?php _e("Date", 'list-category-posts')?>
199
  </p>
200
+
201
  <p>
202
  <input class="checkbox" type="checkbox"
203
  <?php checked( (bool) $instance['show_modified_date'], true ); ?>
include/lcp-widget.php CHANGED
@@ -29,6 +29,7 @@ class ListCategoryPostsWidget extends WP_Widget{
29
  $category_id = $instance['categoryid'];
30
  $dateformat = ($instance['dateformat']) ? $instance['dateformat'] : get_option('date_format');
31
  $showdate = ($instance['show_date'] == 'on') ? 'yes' : 'no';
 
32
  $showmodifieddate = ($instance['show_modified_date'] == 'on') ? 'yes' : 'no';
33
  $showexcerpt = ($instance['show_excerpt'] == 'on') ? 'yes' : 'no';
34
  $excerptsize = (empty($instance['excerpt_size']) ? 55 : $instance['excerpt_size']);
@@ -64,6 +65,10 @@ class ListCategoryPostsWidget extends WP_Widget{
64
  'morelink' => $morelink,
65
  'tags_as_class' => $tags_as_class,
66
  'template' => $template,
 
 
 
 
67
  );
68
 
69
  echo $before_widget;
@@ -81,7 +86,6 @@ class ListCategoryPostsWidget extends WP_Widget{
81
  $title = $lcp_category[0]->name;
82
  }
83
  echo $before_title . $title . $after_title;
84
-
85
  $catlist_displayer = new CatListDisplayer($atts);
86
  echo $catlist_displayer->display();
87
  echo $after_widget;
@@ -111,6 +115,7 @@ class ListCategoryPostsWidget extends WP_Widget{
111
  $instance['morelink'] = strip_tags($new_instance['morelink']);
112
  $instance['tags_as_class'] = strip_tags($new_instance['tags_as_class']);
113
  $instance['template'] = strip_tags($new_instance['template']);
 
114
 
115
  return $instance;
116
  }
29
  $category_id = $instance['categoryid'];
30
  $dateformat = ($instance['dateformat']) ? $instance['dateformat'] : get_option('date_format');
31
  $showdate = ($instance['show_date'] == 'on') ? 'yes' : 'no';
32
+ $pagination = ($instance['pagination'] == 'on') ? 'yes' : 'no';
33
  $showmodifieddate = ($instance['show_modified_date'] == 'on') ? 'yes' : 'no';
34
  $showexcerpt = ($instance['show_excerpt'] == 'on') ? 'yes' : 'no';
35
  $excerptsize = (empty($instance['excerpt_size']) ? 55 : $instance['excerpt_size']);
65
  'morelink' => $morelink,
66
  'tags_as_class' => $tags_as_class,
67
  'template' => $template,
68
+ 'pagination_next' => '>>',
69
+ 'pagination_prev' => '<<',
70
+ 'pagination' => $pagination,
71
+ 'instance' => $this->id
72
  );
73
 
74
  echo $before_widget;
86
  $title = $lcp_category[0]->name;
87
  }
88
  echo $before_title . $title . $after_title;
 
89
  $catlist_displayer = new CatListDisplayer($atts);
90
  echo $catlist_displayer->display();
91
  echo $after_widget;
115
  $instance['morelink'] = strip_tags($new_instance['morelink']);
116
  $instance['tags_as_class'] = strip_tags($new_instance['tags_as_class']);
117
  $instance['template'] = strip_tags($new_instance['template']);
118
+ $instance['pagination'] = strip_tags($new_instance['pagination']);
119
 
120
  return $instance;
121
  }
list-category-posts.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: List category posts
4
  Plugin URI: https://github.com/picandocodigo/List-Category-Posts
5
  Description: List Category Posts allows you to list posts by category in a post/page using the [catlist] shortcode. This shortcode accepts a category name or id, the order in which you want the posts to display, the number of posts to display and many more parameters. You can use [catlist] as many times as needed with different arguments. Usage: [catlist argument1=value1 argument2=value2].
6
- Version: 0.73.2
7
  Author: Fernando Briano
8
  Author URI: http://fernandobriano.com
9
 
3
  Plugin Name: List category posts
4
  Plugin URI: https://github.com/picandocodigo/List-Category-Posts
5
  Description: List Category Posts allows you to list posts by category in a post/page using the [catlist] shortcode. This shortcode accepts a category name or id, the order in which you want the posts to display, the number of posts to display and many more parameters. You can use [catlist] as many times as needed with different arguments. Usage: [catlist argument1=value1 argument2=value2].
6
+ Version: 0.74
7
  Author: Fernando Briano
8
  Author URI: http://fernandobriano.com
9
 
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: list, categories, posts, cms
5
  Requires at least: 3.3
6
  Tested up to: 4.9
7
  Requires PHP: 5.2.4
8
- Stable tag: 0.73.2
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -440,6 +440,10 @@ Template system has changed. Custom templates should be stored in WordPress them
440
 
441
  == Changelog ==
442
 
 
 
 
 
443
  = 0.73.2 =
444
 
445
  * Bug fix release: `[catlist categorypage="yes"]` had stopped working with WordPress 4.9. This is because the category check would compare a return value against the "Empty Term" translation key which was changed [in this commit](https://github.com/WordPress/WordPress/commit/a42b9cebdebb2809b484f4187757555f30c9ee08#diff-efd15818123d55a117706670be80c15aR749) adding periods at the end of some error messages. So it was just a matter of adding the period in the if condition. Thanks helmutka for reporting this!
5
  Requires at least: 3.3
6
  Tested up to: 4.9
7
  Requires PHP: 5.2.4
8
+ Stable tag: 0.74
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
440
 
441
  == Changelog ==
442
 
443
+ = 0.74 =
444
+ * Adds "next" and "previous" classes to the previous and next buttons in pagination menu. The classes are `lcp_prevlink` and `lcp_nextlink`. Thanks @zymeth25.
445
+ * Adds pagination to Widget.
446
+
447
  = 0.73.2 =
448
 
449
  * Bug fix release: `[catlist categorypage="yes"]` had stopped working with WordPress 4.9. This is because the category check would compare a return value against the "Empty Term" translation key which was changed [in this commit](https://github.com/WordPress/WordPress/commit/a42b9cebdebb2809b484f4187757555f30c9ee08#diff-efd15818123d55a117706670be80c15aR749) adding periods at the end of some error messages. So it was just a matter of adding the period in the if condition. Thanks helmutka for reporting this!