List category posts - Version 0.72

Version Description

Several bug fixes:

  • Makes sure the tags_as_class instance variable is defined. This squelched an 'undefined index' PHP Notice that appeared for widgets that were last saved before upgrading to 0.71.1. Fix by Matthew Eppelsheimer (@MatthewEppelsheimer on GitHub).
  • Adds a new tutorial in the docs, check it out!
  • Fixes a bug where customfield_value wouldn't work if a custom field's value
Download this release

Release Info

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

Code changes from version 0.71.1 to 0.72

include/lcp-category.php CHANGED
@@ -60,13 +60,14 @@ class LcpCategory{
60
 
61
  public function current_category(){
62
  $category = get_category( get_query_var( 'category' ) );
63
- if(
64
- isset( $category->errors ) &&
65
- $category->errors["invalid_term"][0] == __("Empty Term")
66
- ){
67
  global $post;
68
  $categories = get_the_category($post->ID);
69
- return $categories[0]->cat_ID;
 
 
 
 
70
  }
71
  return $category->cat_ID;
72
  }
@@ -85,4 +86,4 @@ class LcpCategory{
85
  return ($term) ? $term->term_id : 0;
86
  }
87
 
88
- }
60
 
61
  public function current_category(){
62
  $category = get_category( get_query_var( 'category' ) );
63
+ if( isset( $category->errors ) && $category->errors["invalid_term"][0] == __("Empty Term") ){
 
 
 
64
  global $post;
65
  $categories = get_the_category($post->ID);
66
+ if ( !empty($categories) ){
67
+ return $categories[0]->cat_ID;
68
+ } else {
69
+ return;
70
+ }
71
  }
72
  return $category->cat_ID;
73
  }
86
  return ($term) ? $term->term_id : 0;
87
  }
88
 
89
+ }
include/lcp-catlistdisplayer.php CHANGED
@@ -293,17 +293,7 @@ class CatListDisplayer {
293
 
294
  $lcp_display_output .= $this->get_stuff_with_tags_and_classes('content', $single);
295
 
296
- if (!empty($this->params['excerpt_tag'])):
297
- if (!empty($this->params['excerpt_class'])):
298
- $lcp_display_output .= $this->get_excerpt($single,
299
- $this->params['excerpt_tag'],
300
- $this->params['excerpt_class']);
301
- else:
302
- $lcp_display_output .= $this->get_excerpt($single, $this->params['excerpt_tag']);
303
- endif;
304
- else:
305
- $lcp_display_output .= $this->get_excerpt($single);
306
- endif;
307
 
308
  $lcp_display_output .= $this->get_posts_morelink($single);
309
 
@@ -311,18 +301,28 @@ class CatListDisplayer {
311
  return $lcp_display_output;
312
  }
313
 
 
 
 
 
 
 
314
  private function get_stuff_with_tags_and_classes($entity, $single){
315
  $result = '';
316
  $stuffFunction = 'get_' . $entity;
317
- if (!empty($this->params[$entity . '_tag'])):
318
- if (!empty($this->params[$entity . '_class'])):
 
 
319
  $result = $this->$stuffFunction($single, $this->params[$entity . '_tag'], $this->params[$entity . '_class']);
320
- else:
 
 
321
  $result = $this->$stuffFunction($single, $this->params[$entity . '_tag']);
322
- endif;
323
- else:
324
- $result = $this->$stuffFunction($single);
325
- endif;
326
  return $result;
327
  }
328
 
@@ -355,7 +355,6 @@ class CatListDisplayer {
355
  return $this->content_getter('comments', $single, $tag, $css_class);
356
  }
357
 
358
-
359
  private function get_author($single, $tag = null, $css_class = null){
360
  return $this->content_getter('author', $single, $tag, $css_class);
361
  }
293
 
294
  $lcp_display_output .= $this->get_stuff_with_tags_and_classes('content', $single);
295
 
296
+ $lcp_display_output .= $this->get_stuff_with_tags_and_classes('excerpt', $single);
 
 
 
 
 
 
 
 
 
 
297
 
298
  $lcp_display_output .= $this->get_posts_morelink($single);
299
 
301
  return $lcp_display_output;
302
  }
303
 
304
+ /**
305
+ * Several checks going on here:
306
+ * - Tag provided, no class - wrap content with tag
307
+ * - Tag and class provided - wrap content with tag and class
308
+ * - Class provided, no tag - wrap content with span and class
309
+ */
310
  private function get_stuff_with_tags_and_classes($entity, $single){
311
  $result = '';
312
  $stuffFunction = 'get_' . $entity;
313
+ if (!empty($this->params[$entity . '_class'])){
314
+ if (empty($this->params[$entity . '_tag'])){
315
+ $result = $this->$stuffFunction($single, 'span', $this->params[$entity . '_class']);
316
+ } else {
317
  $result = $this->$stuffFunction($single, $this->params[$entity . '_tag'], $this->params[$entity . '_class']);
318
+ }
319
+ } else {
320
+ if (!empty($this->params[$entity . '_tag'])){
321
  $result = $this->$stuffFunction($single, $this->params[$entity . '_tag']);
322
+ } else {
323
+ $result = $this->$stuffFunction($single);
324
+ }
325
+ }
326
  return $result;
327
  }
328
 
355
  return $this->content_getter('comments', $single, $tag, $css_class);
356
  }
357
 
 
358
  private function get_author($single, $tag = null, $css_class = null){
359
  return $this->content_getter('author', $single, $tag, $css_class);
360
  }
include/lcp-parameters.php CHANGED
@@ -1,350 +1,350 @@
1
- <?php
2
- require_once ( LCP_PATH . 'lcp-utils.php' );
3
-
4
- class LcpParameters{
5
- // Singleton implementation
6
- private static $instance = null;
7
- private $starting_with = null;
8
- // $date_query tells us if we need to generate date_query args
9
- private $date_query = false;
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;
22
- # Essential parameters:
23
- $args = array(
24
- 'numberposts' => $params['numberposts'],
25
- 'orderby' => $params['orderby'],
26
- 'order' => $params['order'],
27
- 'offset' => $params['offset']
28
- );
29
-
30
- if( get_option('lcp_orderby') && $params['orderby'] === ''){
31
- $orderby = array('orderby' => get_option('lcp_orderby'));
32
- $args = array_merge($args, $orderby);
33
- }
34
-
35
- if( get_option('lcp_order') && $params['order'] === ''){
36
- $order = array('order' => get_option('lcp_order'));
37
- $args = array_merge($args, $order);
38
- }
39
-
40
- $this->utils = new LcpUtils($params);
41
-
42
- // Check posts to exclude
43
- $args = $this->lcp_check_excludes($args);
44
-
45
- // Check type, status, parent params
46
- $args = $this->lcp_types_and_statuses($args);
47
-
48
- if($this->utils->lcp_not_empty('year')):
49
- $args['year'] = $params['year'];
50
- endif;
51
-
52
- if($this->utils->lcp_not_empty('monthnum')):
53
- $args['monthnum'] = $params['monthnum'];
54
- endif;
55
-
56
- if($this->utils->lcp_not_empty('search')):
57
- $args['s'] = $params['search'];
58
- endif;
59
-
60
- if($this->utils->lcp_not_empty('author_posts')):
61
- $args['author_name'] = $params['author_posts'];
62
- endif;
63
-
64
- // Posts within given date range:
65
- if ( $this->utils->lcp_not_empty('after') ) {
66
- $this->after = $params['after'];
67
- $date_query = true;
68
- }
69
-
70
- if ( $this->utils->lcp_not_empty('after_year') ) {
71
- $this->after_year = $params['after_year'];
72
- $date_query = true;
73
- }
74
-
75
- if ( $this->utils->lcp_not_empty('after_month') ) {
76
- // after_month should be in the range [1, 12]
77
- if ($params['after_month'] >= 1 && $params['after_month'] <= 12) {
78
- $this->after_month = $params['after_month'];
79
- $date_query = true;
80
- }
81
- }
82
-
83
- if ( $this->utils->lcp_not_empty('after_day') ) {
84
- // after_day should be in the range [1, 31]
85
- if ($params['after_day'] >= 1 && $params['after_day'] <= 31) {
86
- $this->after_day = $params['after_day'];
87
- $date_query = true;
88
- }
89
- }
90
-
91
- if ( $this->utils->lcp_not_empty('before') ) {
92
- $this->before = $params['before'];
93
- $date_query = true;
94
- }
95
-
96
- if ( $this->utils->lcp_not_empty('before_year') ) {
97
- $this->before_year = $params['before_year'];
98
- $date_query = true;
99
- }
100
-
101
- if ( $this->utils->lcp_not_empty('before_month') ) {
102
- // before_month should be in the range [1, 12]
103
- if ($params['before_month'] >= 1 && $params['before_month'] <= 12) {
104
- $this->before_month = $params['before_month'];
105
- $date_query = true;
106
- }
107
- }
108
-
109
- if ( $this->utils->lcp_not_empty('before_day') ) {
110
- // before_day should be in the range [1, 31]
111
- if ($params['before_day'] >= 1 && $params['before_day'] <= 31) {
112
- $this->before_day = $params['before_day'];
113
- $date_query = true;
114
- }
115
- }
116
-
117
- // Only generate date_query args if a before/after paramater was found
118
- if (isset($date_query) ){
119
- $args['date_query'] = $this->create_date_query_args();
120
- }
121
-
122
- /*
123
- * Custom fields 'customfield_name' & 'customfield_value'
124
- * should both be defined
125
- */
126
- if( $this->utils->lcp_not_empty('customfield_value') ){
127
- $args['meta_key'] = $params['customfield_name'];
128
- $args['meta_value'] = $params['customfield_value'];
129
- }
130
-
131
- //Get private posts
132
- if( is_user_logged_in() ){
133
- if ( !empty($args['post_status']) ){
134
- $args['post_status'] = array_merge($args['post_status'], array('private'));
135
- } else{
136
- $args['post_status'] = array('private', 'publish');
137
- }
138
- }
139
-
140
- if ( $this->utils->lcp_not_empty('exclude_tags') ){
141
- $args = $this->lcp_excluded_tags($params);
142
- }
143
-
144
- // Current tags
145
- if ( $this->utils->lcp_not_empty('currenttags') && $params['currenttags'] == "yes" ){
146
- $tags = $this->lcp_get_current_tags();
147
- if ( !empty($tags) ){
148
- $args['tag__in'] = $tags;
149
- }
150
- }
151
-
152
- // Custom taxonomy support
153
- // Why didn't I document this?!?
154
- if ( $this->utils->lcp_not_empty('taxonomy') && $this->utils->lcp_not_empty('terms') ){
155
- $args['tax_query'] = array(array(
156
- 'taxonomy' => $params['taxonomy'],
157
- 'field' => 'slug',
158
- 'terms' => explode(",",$params['terms'])
159
- ));
160
- }
161
-
162
- // Tag support
163
- if ( $this->utils->lcp_not_empty('tags') ) {
164
- $args['tag'] = $params['tags'];
165
- }
166
-
167
- if ( !empty($params['exclude'])){
168
- $args['category__not_in'] = array($params['exclude']);
169
- }
170
-
171
- if ( $this->utils->lcp_not_empty('customfield_orderby') ){
172
- $args['orderby'] = 'meta_value';
173
- $args['meta_key'] = $params['customfield_orderby'];
174
- }
175
-
176
- // Posts that start with a given letter:
177
- if ( $this->utils->lcp_not_empty('starting_with') ){
178
- $this->starting_with = $params['starting_with'];
179
- add_filter('posts_where' , array( $this, 'starting_with') );
180
- }
181
-
182
- return $args;
183
- }
184
-
185
- // Check posts to exclude
186
- private function lcp_check_excludes($args){
187
- if( $this->utils->lcp_not_empty('excludeposts') ){
188
- $exclude = array(
189
- 'post__not_in' => explode(",", $this->params['excludeposts'])
190
- );
191
- if (strpos($this->params['excludeposts'], 'this') > -1){
192
- $exclude = array_merge(
193
- $exclude,
194
- array('post__not_in' => array($this->lcp_get_current_post_id() ) )
195
- );
196
- }
197
- $args = array_merge($args, $exclude);
198
- }
199
- return $args;
200
- }
201
-
202
- private function lcp_types_and_statuses($args){
203
- // Post type, status, parent params:
204
- if($this->utils->lcp_not_empty('post_type')):
205
- $args['post_type'] = explode( ',', $this->params['post_type'] );
206
- endif;
207
-
208
- if($this->utils->lcp_not_empty('post_status')):
209
- $args['post_status'] = explode( ',', $this->params['post_status'] );
210
- endif;
211
-
212
- if($this->utils->lcp_not_empty('post_parent')):
213
- $args['post_parent'] = $this->params['post_parent'];
214
- endif;
215
- return $args;
216
- }
217
-
218
- private function lcp_excluded_tags($args){
219
- $excluded_tags = explode(",", $args['exclude_tags']);
220
- $tag_ids = array();
221
- foreach ( $excluded_tags as $excluded){
222
- $tag_ids[] = get_term_by('slug', $excluded, 'post_tag')->term_id;
223
- }
224
- $args['tag__not_in'] = $tag_ids;
225
- return $args;
226
- }
227
-
228
- private function lcp_get_current_tags(){
229
- $tags = get_the_tags();
230
- $tag_ids = array();
231
- if( !empty($tags) ){
232
- foreach ($tags as $tag) {
233
- array_push($tag_ids, $tag->term_id);
234
- }
235
- }
236
- return $tag_ids;
237
- }
238
-
239
- public function starting_with($where){
240
- $letters = explode(',', $this->starting_with);
241
- $where .= 'AND (wp_posts.post_title ' .
242
- 'COLLATE UTF8_GENERAL_CI LIKE \'' . $letters[0] . "%'";
243
- for ($i=1; $i <sizeof($letters); $i++) {
244
- $where .= 'OR wp_posts.post_title ' .
245
- 'COLLATE UTF8_GENERAL_CI LIKE \'' . $letters[$i] . "%'";
246
- }
247
- $where.=')';
248
- return $where;
249
- }
250
-
251
- private function lcp_get_current_post_id(){
252
- global $post;
253
- return $post->ID;
254
- }
255
-
256
- /*
257
- * Create date_query args according to https://codex.wordpress.org/Class_Reference/WP_Query#Date_Parameters
258
- * There's probably a better way to check if values exist.
259
- * Code should be cleaned up (this is first attempt at a solution).
260
- */
261
- private function create_date_query_args() {
262
- $date_query = array();
263
-
264
- // Keep track of parameters that are set to build the argument array.
265
- $params_set = array(
266
- 'after' => false,
267
- 'after_year' => false,
268
- 'after_month' => false,
269
- 'after_day' => false,
270
- 'before' => false,
271
- 'before_year' => false,
272
- 'before_month' => false,
273
- 'before_day' => false,
274
- );
275
-
276
- // Booleans to track which subarrays should be created.
277
- $after = false;
278
- $before = false;
279
-
280
- /*
281
- * Check which paramaters are set and find out which subarrays
282
- * should be created.
283
- */
284
- if ( isset($this->after) ) {
285
- $params_set['after'] = true;
286
- $after = true;
287
- }
288
-
289
- if ( isset($this->after_year) ) {
290
- $params_set['after_year'] = true;
291
- $after = true;
292
- }
293
-
294
- if ( isset($this->after_month) ) {
295
- $params_set['after_month'] = true;
296
- $after = true;
297
- }
298
-
299
- if ( isset($this->after_day) ) {
300
- $params_set['after_day'] = true;
301
- $after = true;
302
- }
303
-
304
- if ( isset($this->before) ) {
305
- $params_set['before'] = true;
306
- $before = true;
307
- }
308
-
309
- if ( isset($this->before_year) ) {
310
- $params_set['before_year'] = true;
311
- $before = true;
312
- }
313
-
314
- if ( isset($this->before_month) ) {
315
- $params_set['before_month'] = true;
316
- $before = true;
317
- }
318
-
319
- if ( isset($this->before_day) ) {
320
- $params_set['before_day'] = true;
321
- $before = true;
322
- }
323
-
324
- /*
325
- * Build the subarrays.
326
- * The after parameter takes priority over after_* parameters.
327
- * Simlarly, the before parameter takes priority over before_* parameters.
328
- */
329
- if ($after) {
330
- if ($params_set['after']) {
331
- $date_query['after'] = $this->after;
332
- } else {
333
- if ( $params_set['after_year'] ) $date_query['after']['year'] = $this->after_year;
334
- if ( $params_set['after_month'] ) $date_query['after']['month'] = $this->after_month;
335
- if ( $params_set['after_day'] ) $date_query['after']['day'] = $this->after_day;
336
- }
337
- }
338
-
339
- if ($before) {
340
- if ($params_set['before']) {
341
- $date_query['before'] = $this->before;
342
- } else {
343
- if ( $params_set['before_year'] ) $date_query['before']['year'] = $this->before_year;
344
- if ( $params_set['before_month'] ) $date_query['before']['month'] = $this->before_month;
345
- if ( $params_set['before_day'] ) $date_query['before']['day'] = $this->before_day;
346
- }
347
- }
348
- return $date_query;
349
- }
350
- }
1
+ <?php
2
+ require_once ( LCP_PATH . 'lcp-utils.php' );
3
+
4
+ class LcpParameters{
5
+ // Singleton implementation
6
+ private static $instance = null;
7
+ private $starting_with = null;
8
+ // $date_query tells us if we need to generate date_query args
9
+ private $date_query = false;
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;
22
+ # Essential parameters:
23
+ $args = array(
24
+ 'numberposts' => $params['numberposts'],
25
+ 'orderby' => $params['orderby'],
26
+ 'order' => $params['order'],
27
+ 'offset' => $params['offset']
28
+ );
29
+
30
+ if( get_option('lcp_orderby') && $params['orderby'] === ''){
31
+ $orderby = array('orderby' => get_option('lcp_orderby'));
32
+ $args = array_merge($args, $orderby);
33
+ }
34
+
35
+ if( get_option('lcp_order') && $params['order'] === ''){
36
+ $order = array('order' => get_option('lcp_order'));
37
+ $args = array_merge($args, $order);
38
+ }
39
+
40
+ $this->utils = new LcpUtils($params);
41
+
42
+ // Check posts to exclude
43
+ $args = $this->lcp_check_excludes($args);
44
+
45
+ // Check type, status, parent params
46
+ $args = $this->lcp_types_and_statuses($args);
47
+
48
+ if($this->utils->lcp_not_empty('year')):
49
+ $args['year'] = $params['year'];
50
+ endif;
51
+
52
+ if($this->utils->lcp_not_empty('monthnum')):
53
+ $args['monthnum'] = $params['monthnum'];
54
+ endif;
55
+
56
+ if($this->utils->lcp_not_empty('search')):
57
+ $args['s'] = $params['search'];
58
+ endif;
59
+
60
+ if($this->utils->lcp_not_empty('author_posts')):
61
+ $args['author_name'] = $params['author_posts'];
62
+ endif;
63
+
64
+ // Posts within given date range:
65
+ if ( $this->utils->lcp_not_empty('after') ) {
66
+ $this->after = $params['after'];
67
+ $date_query = true;
68
+ }
69
+
70
+ if ( $this->utils->lcp_not_empty('after_year') ) {
71
+ $this->after_year = $params['after_year'];
72
+ $date_query = true;
73
+ }
74
+
75
+ if ( $this->utils->lcp_not_empty('after_month') ) {
76
+ // after_month should be in the range [1, 12]
77
+ if ($params['after_month'] >= 1 && $params['after_month'] <= 12) {
78
+ $this->after_month = $params['after_month'];
79
+ $date_query = true;
80
+ }
81
+ }
82
+
83
+ if ( $this->utils->lcp_not_empty('after_day') ) {
84
+ // after_day should be in the range [1, 31]
85
+ if ($params['after_day'] >= 1 && $params['after_day'] <= 31) {
86
+ $this->after_day = $params['after_day'];
87
+ $date_query = true;
88
+ }
89
+ }
90
+
91
+ if ( $this->utils->lcp_not_empty('before') ) {
92
+ $this->before = $params['before'];
93
+ $date_query = true;
94
+ }
95
+
96
+ if ( $this->utils->lcp_not_empty('before_year') ) {
97
+ $this->before_year = $params['before_year'];
98
+ $date_query = true;
99
+ }
100
+
101
+ if ( $this->utils->lcp_not_empty('before_month') ) {
102
+ // before_month should be in the range [1, 12]
103
+ if ($params['before_month'] >= 1 && $params['before_month'] <= 12) {
104
+ $this->before_month = $params['before_month'];
105
+ $date_query = true;
106
+ }
107
+ }
108
+
109
+ if ( $this->utils->lcp_not_empty('before_day') ) {
110
+ // before_day should be in the range [1, 31]
111
+ if ($params['before_day'] >= 1 && $params['before_day'] <= 31) {
112
+ $this->before_day = $params['before_day'];
113
+ $date_query = true;
114
+ }
115
+ }
116
+
117
+ // Only generate date_query args if a before/after paramater was found
118
+ if (isset($date_query) ){
119
+ $args['date_query'] = $this->create_date_query_args();
120
+ }
121
+
122
+ /*
123
+ * Custom fields 'customfield_name' & 'customfield_value'
124
+ * should both be defined
125
+ */
126
+ if( $this->utils->lcp_not_empty('customfield_name') ){
127
+ $args['meta_key'] = $params['customfield_name'];
128
+ $args['meta_value'] = $params['customfield_value'];
129
+ }
130
+
131
+ //Get private posts
132
+ if( is_user_logged_in() ){
133
+ if ( !empty($args['post_status']) ){
134
+ $args['post_status'] = array_merge($args['post_status'], array('private'));
135
+ } else{
136
+ $args['post_status'] = array('private', 'publish');
137
+ }
138
+ }
139
+
140
+ if ( $this->utils->lcp_not_empty('exclude_tags') ){
141
+ $args = $this->lcp_excluded_tags($params);
142
+ }
143
+
144
+ // Current tags
145
+ if ( $this->utils->lcp_not_empty('currenttags') && $params['currenttags'] == "yes" ){
146
+ $tags = $this->lcp_get_current_tags();
147
+ if ( !empty($tags) ){
148
+ $args['tag__in'] = $tags;
149
+ }
150
+ }
151
+
152
+ // Custom taxonomy support
153
+ // Why didn't I document this?!?
154
+ if ( $this->utils->lcp_not_empty('taxonomy') && $this->utils->lcp_not_empty('terms') ){
155
+ $args['tax_query'] = array(array(
156
+ 'taxonomy' => $params['taxonomy'],
157
+ 'field' => 'slug',
158
+ 'terms' => explode(",",$params['terms'])
159
+ ));
160
+ }
161
+
162
+ // Tag support
163
+ if ( $this->utils->lcp_not_empty('tags') ) {
164
+ $args['tag'] = $params['tags'];
165
+ }
166
+
167
+ if ( !empty($params['exclude'])){
168
+ $args['category__not_in'] = array($params['exclude']);
169
+ }
170
+
171
+ if ( $this->utils->lcp_not_empty('customfield_orderby') ){
172
+ $args['orderby'] = 'meta_value';
173
+ $args['meta_key'] = $params['customfield_orderby'];
174
+ }
175
+
176
+ // Posts that start with a given letter:
177
+ if ( $this->utils->lcp_not_empty('starting_with') ){
178
+ $this->starting_with = $params['starting_with'];
179
+ add_filter('posts_where' , array( $this, 'starting_with') );
180
+ }
181
+
182
+ return $args;
183
+ }
184
+
185
+ // Check posts to exclude
186
+ private function lcp_check_excludes($args){
187
+ if( $this->utils->lcp_not_empty('excludeposts') ){
188
+ $exclude = array(
189
+ 'post__not_in' => explode(",", $this->params['excludeposts'])
190
+ );
191
+ if (strpos($this->params['excludeposts'], 'this') > -1){
192
+ $exclude = array_merge(
193
+ $exclude,
194
+ array('post__not_in' => array($this->lcp_get_current_post_id() ) )
195
+ );
196
+ }
197
+ $args = array_merge($args, $exclude);
198
+ }
199
+ return $args;
200
+ }
201
+
202
+ private function lcp_types_and_statuses($args){
203
+ // Post type, status, parent params:
204
+ if($this->utils->lcp_not_empty('post_type')):
205
+ $args['post_type'] = explode( ',', $this->params['post_type'] );
206
+ endif;
207
+
208
+ if($this->utils->lcp_not_empty('post_status')):
209
+ $args['post_status'] = explode( ',', $this->params['post_status'] );
210
+ endif;
211
+
212
+ if($this->utils->lcp_not_empty('post_parent')):
213
+ $args['post_parent'] = $this->params['post_parent'];
214
+ endif;
215
+ return $args;
216
+ }
217
+
218
+ private function lcp_excluded_tags($args){
219
+ $excluded_tags = explode(",", $args['exclude_tags']);
220
+ $tag_ids = array();
221
+ foreach ( $excluded_tags as $excluded){
222
+ $tag_ids[] = get_term_by('slug', $excluded, 'post_tag')->term_id;
223
+ }
224
+ $args['tag__not_in'] = $tag_ids;
225
+ return $args;
226
+ }
227
+
228
+ private function lcp_get_current_tags(){
229
+ $tags = get_the_tags();
230
+ $tag_ids = array();
231
+ if( !empty($tags) ){
232
+ foreach ($tags as $tag) {
233
+ array_push($tag_ids, $tag->term_id);
234
+ }
235
+ }
236
+ return $tag_ids;
237
+ }
238
+
239
+ public function starting_with($where){
240
+ $letters = explode(',', $this->starting_with);
241
+ $where .= 'AND (wp_posts.post_title ' .
242
+ 'COLLATE UTF8_GENERAL_CI LIKE \'' . $letters[0] . "%'";
243
+ for ($i=1; $i <sizeof($letters); $i++) {
244
+ $where .= 'OR wp_posts.post_title ' .
245
+ 'COLLATE UTF8_GENERAL_CI LIKE \'' . $letters[$i] . "%'";
246
+ }
247
+ $where.=')';
248
+ return $where;
249
+ }
250
+
251
+ private function lcp_get_current_post_id(){
252
+ global $post;
253
+ return $post->ID;
254
+ }
255
+
256
+ /*
257
+ * Create date_query args according to https://codex.wordpress.org/Class_Reference/WP_Query#Date_Parameters
258
+ * There's probably a better way to check if values exist.
259
+ * Code should be cleaned up (this is first attempt at a solution).
260
+ */
261
+ private function create_date_query_args() {
262
+ $date_query = array();
263
+
264
+ // Keep track of parameters that are set to build the argument array.
265
+ $params_set = array(
266
+ 'after' => false,
267
+ 'after_year' => false,
268
+ 'after_month' => false,
269
+ 'after_day' => false,
270
+ 'before' => false,
271
+ 'before_year' => false,
272
+ 'before_month' => false,
273
+ 'before_day' => false,
274
+ );
275
+
276
+ // Booleans to track which subarrays should be created.
277
+ $after = false;
278
+ $before = false;
279
+
280
+ /*
281
+ * Check which paramaters are set and find out which subarrays
282
+ * should be created.
283
+ */
284
+ if ( isset($this->after) ) {
285
+ $params_set['after'] = true;
286
+ $after = true;
287
+ }
288
+
289
+ if ( isset($this->after_year) ) {
290
+ $params_set['after_year'] = true;
291
+ $after = true;
292
+ }
293
+
294
+ if ( isset($this->after_month) ) {
295
+ $params_set['after_month'] = true;
296
+ $after = true;
297
+ }
298
+
299
+ if ( isset($this->after_day) ) {
300
+ $params_set['after_day'] = true;
301
+ $after = true;
302
+ }
303
+
304
+ if ( isset($this->before) ) {
305
+ $params_set['before'] = true;
306
+ $before = true;
307
+ }
308
+
309
+ if ( isset($this->before_year) ) {
310
+ $params_set['before_year'] = true;
311
+ $before = true;
312
+ }
313
+
314
+ if ( isset($this->before_month) ) {
315
+ $params_set['before_month'] = true;
316
+ $before = true;
317
+ }
318
+
319
+ if ( isset($this->before_day) ) {
320
+ $params_set['before_day'] = true;
321
+ $before = true;
322
+ }
323
+
324
+ /*
325
+ * Build the subarrays.
326
+ * The after parameter takes priority over after_* parameters.
327
+ * Simlarly, the before parameter takes priority over before_* parameters.
328
+ */
329
+ if ($after) {
330
+ if ($params_set['after']) {
331
+ $date_query['after'] = $this->after;
332
+ } else {
333
+ if ( $params_set['after_year'] ) $date_query['after']['year'] = $this->after_year;
334
+ if ( $params_set['after_month'] ) $date_query['after']['month'] = $this->after_month;
335
+ if ( $params_set['after_day'] ) $date_query['after']['day'] = $this->after_day;
336
+ }
337
+ }
338
+
339
+ if ($before) {
340
+ if ($params_set['before']) {
341
+ $date_query['before'] = $this->before;
342
+ } else {
343
+ if ( $params_set['before_year'] ) $date_query['before']['year'] = $this->before_year;
344
+ if ( $params_set['before_month'] ) $date_query['before']['month'] = $this->before_month;
345
+ if ( $params_set['before_day'] ) $date_query['before']['day'] = $this->before_day;
346
+ }
347
+ }
348
+ return $date_query;
349
+ }
350
+ }
include/lcp-widget.php CHANGED
@@ -37,6 +37,9 @@ class ListCategoryPostsWidget extends WP_Widget{
37
  $thumbnail = ($instance['thumbnail'] == 'on') ? 'yes' : 'no';
38
  $thumbnail_size = ($instance['thumbnail_size']) ? $instance['thumbnail_size'] : 'thumbnail';
39
  $morelink = empty($instance['morelink']) ? ' ' : $instance['morelink'];
 
 
 
40
  $tags_as_class = ($instance['tags_as_class'] == 'yes') ? 'yes' : 'no';
41
  $template = empty($instance['template']) ? 'default' : $instance['template'];
42
 
37
  $thumbnail = ($instance['thumbnail'] == 'on') ? 'yes' : 'no';
38
  $thumbnail_size = ($instance['thumbnail_size']) ? $instance['thumbnail_size'] : 'thumbnail';
39
  $morelink = empty($instance['morelink']) ? ' ' : $instance['morelink'];
40
+ if ( empty( $instance['tags_as_class'] ) ) {
41
+ $instance['tags_as_class'] = 'no';
42
+ }
43
  $tags_as_class = ($instance['tags_as_class'] == 'yes') ? 'yes' : 'no';
44
  $template = empty($instance['template']) ? 'default' : $instance['template'];
45
 
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.71.1
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.72
7
  Author: Fernando Briano
8
  Author URI: http://fernandobriano.com
9
 
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: fernandobt
3
  Donate Link: http://picandocodigo.net/programacion/wordpress/list-category-posts-wordpress-plugin-english/#support
4
  Tags: list, categories, posts, cms
5
  Requires at least: 3.3
6
- Tested up to: 4.7.2
7
- Stable tag: 0.71.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -46,7 +46,7 @@ You can find **Frequently Asked Questions** [here](https://github.com/picandocod
46
 
47
  **Customization**
48
 
49
- The different elements to display can be styled with CSS. you can define an HTML tag to wrap the element with, and a CSS class for this tag. Check [the documentation](https://github.com/picandocodigo/List-Category-Posts/wiki) for usage.
50
 
51
  Great to use WordPress as a CMS, and create pages with several categories posts.
52
 
@@ -65,10 +65,9 @@ to be aware of new functionality, and improvements to the plugin.
65
 
66
  **Videos**
67
 
68
- Some users have made videos on how to use the plugin, (thank you! you people are awesome!). Check them out here:
69
 
70
  * [Manage WordPress Content with List Category Posts Plugin](http://www.youtube.com/watch?v=kBy_qoGKpdo)
71
- * [Build A Start Here Page with List Category Posts](http://www.youtube.com/watch?v=9YJpZfHIwIY)
72
  * [WordPress: How to List Category Posts on a Page](http://www.youtube.com/watch?v=Zfnzk4IWPNA)
73
 
74
  **Support the plugin**
@@ -175,7 +174,7 @@ When using List Category Posts whithout a category id, name or slug, it will pos
175
  * **post_parent** - Show only the children of the post with this ID.
176
  Default: None.
177
 
178
- * **custom fields** - To use custom fields, you must specify two values: customfield_name and customfield_value. Using this only show posts that contain a custom field with this name and value. Both parameters must be defined, or neither will work.
179
 
180
  ==PAGINATION
181
 
@@ -416,7 +415,7 @@ You can post them on [GitHub Issues](https://github.com/picandocodigo/List-Categ
416
 
417
  **FURTHER QUESTIONS**
418
 
419
- For questions either use the [Support forum](http://wordpress.org/support/plugin/list-category-posts) or [WordPress Answers](http://wordpress.stackexchange.com/) (just [ask your question](http://wordpress.stackexchange.com/questions/ask?tags=plugin-list-category-posts) using the 'plugin-list-category-post' tag).
420
 
421
  == Upgrade Notice ==
422
 
@@ -458,6 +457,20 @@ Template system has changed. Custom templates should be stored in WordPress them
458
 
459
  == Changelog ==
460
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
461
  = 0.71.1 =
462
 
463
  * Fixes ["Undefined index: tags_as_class"](https://github.com/picandocodigo/List-Category-Posts/issues/227). Thanks @vacuus for the Pull Request! :)
3
  Donate Link: http://picandocodigo.net/programacion/wordpress/list-category-posts-wordpress-plugin-english/#support
4
  Tags: list, categories, posts, cms
5
  Requires at least: 3.3
6
+ Tested up to: 4.7.3
7
+ Stable tag: 0.72
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
46
 
47
  **Customization**
48
 
49
+ The different elements to display can be styled with CSS. you can define an HTML tag to wrap the element with, and a CSS class for this tag. Check [the documentation](https://github.com/picandocodigo/List-Category-Posts/wiki) for usage. You can also check [this nice tutorial](http://sundari-webdesign.com/wordpress-the-quest-to-my-perfect-list-view-for-posts-events-and-articles/) which gives lots of tips and how-to's to customize how to display the posts.
50
 
51
  Great to use WordPress as a CMS, and create pages with several categories posts.
52
 
65
 
66
  **Videos**
67
 
68
+ Some users have made videos on how to use the plugin (thank you, you are awesome!), check them out here:
69
 
70
  * [Manage WordPress Content with List Category Posts Plugin](http://www.youtube.com/watch?v=kBy_qoGKpdo)
 
71
  * [WordPress: How to List Category Posts on a Page](http://www.youtube.com/watch?v=Zfnzk4IWPNA)
72
 
73
  **Support the plugin**
174
  * **post_parent** - Show only the children of the post with this ID.
175
  Default: None.
176
 
177
+ * **custom fields** - To use custom fields, you must specify two values: customfield_name and customfield_value. `customfield_name` defines the name of the field, and you should choose the values for which you want posts to display. Using this only show posts that contain a custom field with this name and value. Both parameters must be defined, or neither will work. Eg: `[catlist customfield_name="color" customfield_value="green"]` will display posts with the value `green` set on the custom field `color`.
178
 
179
  ==PAGINATION
180
 
415
 
416
  **FURTHER QUESTIONS**
417
 
418
+ Please check the [FAQ](https://github.com/picandocodigo/List-Category-Posts/blob/master/doc/FAQ.md#frequently-asked-questions) before posting a question. You can post questions in the [Support forum](http://wordpress.org/support/plugin/list-category-posts) or [add a new issue on GitHub](https://github.com/picandocodigo/List-Category-Posts/issues).
419
 
420
  == Upgrade Notice ==
421
 
457
 
458
  == Changelog ==
459
 
460
+ = 0.72 =
461
+
462
+ Several bug fixes:
463
+
464
+ * Makes sure the `tags_as_class` instance variable is defined. This squelched an 'undefined index' PHP Notice that appeared for widgets that were last saved before upgrading to 0.71.1. Fix by Matthew Eppelsheimer (@MatthewEppelsheimer on GitHub).
465
+ * Adds a new tutorial in the docs, check it out!
466
+ * Fixes a bug where customfield_value wouldn't work if a custom field's value = 0
467
+ * Adds tag/class html customization refactor to excerpt to behave as expected:
468
+ * If you provide `excerpt_tag` but not `excerpt_class`, excerpt will be wrapped with given tag.
469
+ * If you provide `excerpt_tag` and `excerpt_class`, excerpt will be wrapped with provided tag and given class.
470
+ * If you provide `excerpt_class` but not `excerpt_tag`, excerpt will be wrapped with a span and the given class.
471
+ * Fixes an error notice when widget is displayed for "current category" on post without category - `Notice: Undefined offset: 0 in /include/lcp-category.php on line 69`
472
+
473
+
474
  = 0.71.1 =
475
 
476
  * Fixes ["Undefined index: tags_as_class"](https://github.com/picandocodigo/List-Category-Posts/issues/227). Thanks @vacuus for the Pull Request! :)