List category posts - Version 0.64

Version Description

  • Fixes get_current_tags
  • Some updates on the documentation
  • Introduces a conditional title, only displayed when posts are found, thanks bibz for this Pull Request!
  • Introduces customfield_display_separately, customfield_display_glue and customfield_display_name_glue parameters for multiple custom fields handling by bibz. Thanks! :D
Download this release

Release Info

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

Code changes from version 0.63.1 to 0.64

include/lcp-catlist.php CHANGED
@@ -213,42 +213,45 @@ class CatList{
213
  endif;
214
  }
215
 
 
 
 
 
 
 
216
  /**
217
- * Display custom fields.
218
  * @see http://codex.wordpress.org/Function_Reference/get_post_custom
219
  * @param string $custom_key
220
  * @param int $post_id
221
  */
222
  public function get_custom_fields($custom_key, $post_id){
223
- if( $this->utils->lcp_not_empty('customfield_display') &&
224
- ( $this->params['customfield_display'] != '') ):
225
- $lcp_customs = '';
226
-
227
- //Doesn't work for many custom fields when having spaces:
228
- $custom_key = trim($custom_key);
229
-
230
- //Create array for many fields:
231
- $custom_array = explode(",", $custom_key);
232
-
233
- //Get post custom fields:
234
- $custom_fields = get_post_custom($post_id);
235
-
236
- //Loop on custom fields and if there's a value, add it:
237
- foreach ($custom_array as $user_customfield) :
238
- if(isset($custom_fields[$user_customfield])):
239
- $my_custom_field = $custom_fields[$user_customfield];
240
-
241
- if (sizeof($my_custom_field) > 0 ):
242
- foreach ( $my_custom_field as $key => $value ) :
243
- if ($this->params['customfield_display_name'] != "no")
244
- $lcp_customs .= $user_customfield . " : ";
245
- $lcp_customs .= $value;
246
- endforeach;
247
- endif;
248
- endif;
249
- endforeach;
250
 
251
- return $lcp_customs;
252
  else:
253
  return null;
254
  endif;
213
  endif;
214
  }
215
 
216
+ public function get_conditional_title(){
217
+ if($this->utils->lcp_not_empty('conditional_title') && $this->get_posts_count() > 0):
218
+ return trim($this->params['conditional_title']);
219
+ endif;
220
+ }
221
+
222
  /**
223
+ * Array of custom fields.
224
  * @see http://codex.wordpress.org/Function_Reference/get_post_custom
225
  * @param string $custom_key
226
  * @param int $post_id
227
  */
228
  public function get_custom_fields($custom_key, $post_id){
229
+ if ( $this->utils->lcp_not_empty( 'customfield_display' ) ) :
230
+ $lcp_customs = array();
231
+
232
+ //Doesn't work for many custom fields when having spaces:
233
+ $custom_key = trim( $custom_key );
234
+
235
+ //Create array for many fields:
236
+ $custom_array = explode( ',', $custom_key );
237
+
238
+ //Get post custom fields:
239
+ $custom_fields = get_post_custom( $post_id );
240
+
241
+ //Loop on custom fields and if there's a value, add it:
242
+ foreach ( $custom_array as $user_customfield ) :
243
+ // Check that the custom field is wanted:
244
+ if ( isset( $custom_fields[$user_customfield] ) ) :
245
+ //Browse through the custom field values:
246
+ foreach ( $custom_fields[$user_customfield] as $key => $value ) :
247
+ if ( $this->params['customfield_display_name'] != 'no' )
248
+ $value = $user_customfield . $this->params['customfield_display_name_glue'] . $value;
249
+ $lcp_customs[] = $value;
250
+ endforeach;
251
+ endif;
252
+ endforeach;
 
 
 
253
 
254
+ return $lcp_customs;
255
  else:
256
  return null;
257
  endif;
include/lcp-catlistdisplayer.php CHANGED
@@ -124,6 +124,8 @@ class CatListDisplayer {
124
  $this->lcp_output .= '>';
125
  $inner_tag = ( ($tag == 'ul') || ($tag == 'ol') ) ? 'li' : 'p';
126
 
 
 
127
  //Posts loop
128
  global $post;
129
  while ( have_posts() ) : the_post();
@@ -364,6 +366,19 @@ class CatListDisplayer {
364
  return $this->assign_style($info, $tag, $css_class);
365
  }
366
 
 
 
 
 
 
 
 
 
 
 
 
 
 
367
  private function get_custom_fields($single){
368
  if(!empty($this->params['customfield_display'])){
369
  $info = $this->catlist->get_custom_fields($this->params['customfield_display'], $single->ID);
@@ -371,7 +386,19 @@ class CatListDisplayer {
371
  $tag = 'div';
372
  if(empty($this->params['customfield_class']) || $this->params['customfield_class'] == null)
373
  $css_class = 'lcp_customfield';
374
- return $this->assign_style($info, $tag, $css_class);
 
 
 
 
 
 
 
 
 
 
 
 
375
  }
376
  }
377
 
124
  $this->lcp_output .= '>';
125
  $inner_tag = ( ($tag == 'ul') || ($tag == 'ol') ) ? 'li' : 'p';
126
 
127
+ $this->lcp_output .= $this->get_conditional_title();
128
+
129
  //Posts loop
130
  global $post;
131
  while ( have_posts() ) : the_post();
366
  return $this->assign_style($info, $tag, $css_class);
367
  }
368
 
369
+ private function get_conditional_title(){
370
+ if(!empty($this->params['conditional_title_tag']))
371
+ $tag = $this->params['conditional_title_tag'];
372
+ else
373
+ $tag = 'h3';
374
+ if(!empty($this->params['conditional_title_class']))
375
+ $class = $this->params['conditional_title_class'];
376
+ else
377
+ $class = '';
378
+
379
+ return $this->assign_style($this->catlist->get_conditional_title(), $tag, $class);
380
+ }
381
+
382
  private function get_custom_fields($single){
383
  if(!empty($this->params['customfield_display'])){
384
  $info = $this->catlist->get_custom_fields($this->params['customfield_display'], $single->ID);
386
  $tag = 'div';
387
  if(empty($this->params['customfield_class']) || $this->params['customfield_class'] == null)
388
  $css_class = 'lcp_customfield';
389
+ $final_info = '';
390
+ if(!is_array($info)){
391
+ $final_info = $this->assign_style($info, $tag, $css_class);
392
+ }else{
393
+ if($this->params['customfield_display_separately'] != 'no'){
394
+ foreach($info as $i)
395
+ $final_info .= $this->assign_style($i, $tag, $css_class);
396
+ }else{
397
+ $one_info = implode($this->params['customfield_display_glue'], $info);
398
+ $final_info = $this->assign_style($one_info, $tag, $css_class);
399
+ }
400
+ }
401
+ return $final_info;
402
  }
403
  }
404
 
include/lcp-parameters.php CHANGED
@@ -154,8 +154,8 @@ class LcpParameters{
154
  $tags = get_the_tags();
155
  $tag_ids = array();
156
  if( !empty($tags) ){
157
- foreach ($tags as $tag_id => $tag) {
158
- array_push($tag_ids, $tag_id);
159
  }
160
  }
161
  return $tag_ids;
154
  $tags = get_the_tags();
155
  $tag_ids = array();
156
  if( !empty($tags) ){
157
+ foreach ($tags as $tag) {
158
+ array_push($tag_ids, $tag->term_id);
159
  }
160
  }
161
  return $tag_ids;
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.63.1
7
  Author: Fernando Briano
8
  Author URI: http://fernandobriano.com
9
 
@@ -95,10 +95,16 @@ class ListCategoryPosts{
95
  'post_suffix' => '',
96
  'show_protected' => 'no',
97
  'class' => 'lcp_catlist',
 
 
 
98
  'customfield_name' => '',
99
  'customfield_value' =>'',
100
  'customfield_display' =>'',
 
101
  'customfield_display_name' =>'',
 
 
102
  'customfield_orderby' =>'',
103
  'customfield_tag' => '',
104
  'customfield_class' => '',
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.64
7
  Author: Fernando Briano
8
  Author URI: http://fernandobriano.com
9
 
95
  'post_suffix' => '',
96
  'show_protected' => 'no',
97
  'class' => 'lcp_catlist',
98
+ 'conditional_title' => '',
99
+ 'conditional_title_tag' => '',
100
+ 'conditional_title_class' => '',
101
  'customfield_name' => '',
102
  'customfield_value' =>'',
103
  'customfield_display' =>'',
104
+ 'customfield_display_glue' => '',
105
  'customfield_display_name' =>'',
106
+ 'customfield_display_name_glue' => ' : ',
107
+ 'customfield_display_separately' => 'no',
108
  'customfield_orderby' =>'',
109
  'customfield_tag' => '',
110
  'customfield_class' => '',
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate Link: http://picandocodigo.net/programacion/wordpress/list-category-posts
4
  Tags: list, categories, posts, cms
5
  Requires at least: 3.3
6
  Tested up to: 4.3
7
- Stable tag: 0.63.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -60,7 +60,7 @@ Some users have made videos on how to use the plugin, (thank you! you people are
60
 
61
  **Support the plugin**
62
 
63
- If you've found the plugin useful, consider making a [donation via PayPal](http://picandocodigo.net/programacion/wordpress/list-category-posts-wordpress-plugin-english/ "Donate via PayPal") or visit my Amazon Wishlist for [books](http://www.amazon.com/gp/registry/wishlist/2HU1JYOF7DX5Q/ref=wl_web "Amazon Wishlist") or [comic books](http://www.amazon.com/registry/wishlist/1LVYAOJAZQOI0/ref=cm_wl_rlist_go_o) :).
64
 
65
  **Development**
66
 
@@ -136,13 +136,24 @@ update the plugin.
136
 
137
  ==Other parameters==
138
 
 
 
 
 
 
 
 
 
 
 
 
139
  * **author_posts** - Get posts by author. Use 'user_nicename' (NOT
140
  name). Example: `[catlist author_posts="fernando"]`
141
 
142
  * **tags** - Tag support, display posts from a certain tag.
143
 
144
  * **currenttags** - Display posts from the current post's tags (won't
145
- work on pages since they have no tags).
146
 
147
  * **exclude_tags** - Exclude posts from one or more tags: `[catlist tags="videogames" exclude_tags="sega,sony"]`
148
 
@@ -298,6 +309,15 @@ Show the full content of the post regardless of whether there is a <!--more--
298
  set a different tag (instead of the div) and a specific class
299
  (instead of lcp-customfield).
300
 
 
 
 
 
 
 
 
 
 
301
  * **customfield_display_name** - To use with `customfield_display`.
302
  Use it to just print the value of the Custom field and not the
303
  name. Example:
@@ -306,6 +326,10 @@ Show the full content of the post regardless of whether there is a <!--more--
306
  Will print the value of the Custom Field "Mood" but not the text
307
  "Mood: [value]".
308
 
 
 
 
 
309
  * **template** - By default, posts will be listed in an unordered list
310
  (ul tag) with the class 'lcp_catlist':
311
 
@@ -391,7 +415,7 @@ class will be assigned to the `a` tag like this:
391
  Will produce:
392
  `<a href="http://127.0.0.1/wordpress/?p=38" title="Test" class="lcp_title">Test</a>`
393
  But if you use both:
394
- `[catlist numberposts=5 title_class=lcp_title tag=h4]`
395
  You will get:
396
  `<h4 class="lcp_title">
397
  <a title="Hipchat" href="http://127.0.0.1:8080/wordpress/?p=40"></a>
@@ -451,6 +475,13 @@ Template system has changed. Custom templates should be stored in WordPress them
451
 
452
  == Changelog ==
453
 
 
 
 
 
 
 
 
454
  = 0.63.1 =
455
  * Remove renamed file (Damn using subversion), should fix issues updating.
456
 
4
  Tags: list, categories, posts, cms
5
  Requires at least: 3.3
6
  Tested up to: 4.3
7
+ Stable tag: 0.64
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
60
 
61
  **Support the plugin**
62
 
63
+ If you've found the plugin useful, consider making a [donation via PayPal](http://picandocodigo.net/programacion/wordpress/list-category-posts-wordpress-plugin-english/#support "Donate via PayPal") or visit my Amazon Wishlist for [books](http://www.amazon.com/gp/registry/wishlist/2HU1JYOF7DX5Q/ref=wl_web "Amazon Wishlist") or [comic books](http://www.amazon.com/registry/wishlist/1LVYAOJAZQOI0/ref=cm_wl_rlist_go_o) :).
64
 
65
  **Development**
66
 
136
 
137
  ==Other parameters==
138
 
139
+ * **conditional_title** - Display a custom title before the posts list.
140
+ The title is not displayed if the list is empty. Set to the empty string
141
+ (default value) to disable.
142
+ Example: `[catlist conditional_title="Other posts"]`.
143
+
144
+ * **conditional_title_tag** - Specify the tag used for the conditional title.
145
+ Defaults to 'h3'.
146
+
147
+ * **conditional_title_class** - Specify the class used for the conditional
148
+ title. Defaults to the empty string (no special class).
149
+
150
  * **author_posts** - Get posts by author. Use 'user_nicename' (NOT
151
  name). Example: `[catlist author_posts="fernando"]`
152
 
153
  * **tags** - Tag support, display posts from a certain tag.
154
 
155
  * **currenttags** - Display posts from the current post's tags (won't
156
+ work on pages since they have no tags). Pass it the 'yes' string for it to work: `[catlist currenttags="yes"]`
157
 
158
  * **exclude_tags** - Exclude posts from one or more tags: `[catlist tags="videogames" exclude_tags="sega,sony"]`
159
 
309
  set a different tag (instead of the div) and a specific class
310
  (instead of lcp-customfield).
311
 
312
+ * **customfield_display_glue** - Specify the text to appear between two custom
313
+ fields if displayed together, defaults to the empty string. Not used if
314
+ the `customfield_display_separately` parameter is defined.
315
+
316
+ * **customfield_display_separately** - Display the custom fields separately.
317
+ Each custom field is displayd within its own tag (see `customfield_tag`).
318
+ Defaults to 'no', set to 'yes' to enable. Superseeds the
319
+ `customfield_display_glue` parameter when enabled.
320
+
321
  * **customfield_display_name** - To use with `customfield_display`.
322
  Use it to just print the value of the Custom field and not the
323
  name. Example:
326
  Will print the value of the Custom Field "Mood" but not the text
327
  "Mood: [value]".
328
 
329
+ * **customfield_display_name_glue** - To use with `customfield_display_name`.
330
+ Use it to specify the text between the name and the value, defaults to
331
+ ' : '.
332
+
333
  * **template** - By default, posts will be listed in an unordered list
334
  (ul tag) with the class 'lcp_catlist':
335
 
415
  Will produce:
416
  `<a href="http://127.0.0.1/wordpress/?p=38" title="Test" class="lcp_title">Test</a>`
417
  But if you use both:
418
+ `[catlist numberposts=5 title_class=lcp_title title_tag=h4]`
419
  You will get:
420
  `<h4 class="lcp_title">
421
  <a title="Hipchat" href="http://127.0.0.1:8080/wordpress/?p=40"></a>
475
 
476
  == Changelog ==
477
 
478
+ = 0.64 =
479
+
480
+ * Fixes get_current_tags
481
+ * Some updates on the documentation
482
+ * Introduces a conditional title, only displayed when posts are found, thanks [bibz](https://github.com/bibz) for this Pull Request!
483
+ * Introduces `customfield_display_separately`, `customfield_display_glue` and `customfield_display_name_glue` parameters for multiple custom fields handling by bibz. Thanks! :D
484
+
485
  = 0.63.1 =
486
  * Remove renamed file (Damn using subversion), should fix issues updating.
487
 
templates/default.php CHANGED
@@ -37,6 +37,9 @@ $lcp_display_output = '';
37
  // Show category link:
38
  $lcp_display_output .= $this->get_category_link('strong');
39
 
 
 
 
40
  //Add 'starting' tag. Here, I'm using an unordered list (ul) as an example:
41
  $lcp_display_output .= '<ul class="lcp_catlist">';
42
 
37
  // Show category link:
38
  $lcp_display_output .= $this->get_category_link('strong');
39
 
40
+ // Show the conditional title:
41
+ $lcp_display_output .= $this->get_conditional_title();
42
+
43
  //Add 'starting' tag. Here, I'm using an unordered list (ul) as an example:
44
  $lcp_display_output .= '<ul class="lcp_catlist">';
45