List category posts - Version 0.50

Version Description

  • Adds Thai translation by itpcc.
    • The widget can now select an existing template. Thanks Borjan Tchakaloff!
    • Templates code was refactored.
Download this release

Release Info

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

Code changes from version 0.49.1 to 0.50

include/CatList.php CHANGED
@@ -317,7 +317,9 @@ class CatList{
317
  * Load category name and link to the category:
318
  */
319
  public function get_category_link(){
320
- if( ($this->params['catlink'] == 'yes' || $this->params['catname'] == 'yes') &&
 
 
321
  $this->lcp_category_id != 0):
322
  // Check for one id or several:
323
  $ids = null;
317
  * Load category name and link to the category:
318
  */
319
  public function get_category_link(){
320
+ if( $this->lcp_not_empty('catlink_string') &&
321
+ ($this->params['catlink'] == 'yes' ||
322
+ $this->params['catname'] == 'yes') &&
323
  $this->lcp_category_id != 0):
324
  // Check for one id or several:
325
  $ids = null;
include/CatListDisplayer.php CHANGED
@@ -10,52 +10,88 @@ class CatListDisplayer {
10
  private $catlist;
11
  private $params = array();
12
  private $lcp_output;
 
 
 
 
 
13
 
14
  public function __construct($atts) {
15
  $this->params = $atts;
16
  $this->catlist = new CatList($atts);
17
- $this->template();
18
  }
19
 
20
  public function display(){
21
  return $this->lcp_output;
22
  }
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  /**
25
  * Template code
26
  */
27
  private function template(){
28
  $tplFileName = null;
29
- $possibleTemplates = array(
30
- // File locations lower in list override others
31
- TEMPLATEPATH.'/list-category-posts/'.$this->params['template'].'.php',
32
- STYLESHEETPATH.'/list-category-posts/'.$this->params['template'].'.php'
33
- );
34
-
35
- foreach ($possibleTemplates as $key => $file) :
36
- if ( is_readable($file) ) :
 
 
 
 
 
 
 
37
  $tplFileName = $file;
38
  endif;
39
  endforeach;
40
 
41
- if ( !empty($tplFileName) && is_readable($tplFileName) ) :
42
  require($tplFileName);
43
- else:
44
- switch($this->params['template']):
45
- case "default":
46
- $this->build_output('ul');
47
- break;
48
- case "div":
49
- $this->build_output('div');
50
- break;
51
- case "ol":
52
- $this->build_output('ol');
53
- break;
54
- default:
55
- $this->build_output('ul');
56
- break;
57
- endswitch;
58
- endif;
 
 
 
 
 
 
59
  }
60
 
61
  private function build_output($tag){
10
  private $catlist;
11
  private $params = array();
12
  private $lcp_output;
13
+ public static function getTemplatePaths(){
14
+ $template_path = TEMPLATEPATH . "/list-category-posts/";
15
+ $stylesheet_path = STYLESHEETPATH . "/list-category-posts/";
16
+ return array($template_path, $stylesheet_path);
17
+ }
18
 
19
  public function __construct($atts) {
20
  $this->params = $atts;
21
  $this->catlist = new CatList($atts);
22
+ $this->define_template();
23
  }
24
 
25
  public function display(){
26
  return $this->lcp_output;
27
  }
28
 
29
+ private function define_template(){
30
+ // Check if we got a template param:
31
+ if (isset($this->params['template']) &&
32
+ !empty($this->params['template']) &&
33
+ $this->params['template'] != 'default'){
34
+ // The default values for ul, ol and div:
35
+ if (preg_match('/^ul$|^div$|^ol$/i', $this->params['template'], $matches)){
36
+ $this->build_output($matches[0]);
37
+ } else {
38
+ // Else try an actual template from the params
39
+ $this->template();
40
+ }
41
+ } else {
42
+ // Default:
43
+ $this->build_output('ul');
44
+ }
45
+ }
46
+
47
  /**
48
  * Template code
49
  */
50
  private function template(){
51
  $tplFileName = null;
52
+ $template_param = $this->params['template'];
53
+ $templates = array();
54
+
55
+ // Get templates paths and add the incoming parameter to search
56
+ // for the php file:
57
+ if($template_param){
58
+ $paths = self::getTemplatePaths();
59
+ foreach($paths as $path){
60
+ $templates[] = $path . $template_param . '.php';
61
+ }
62
+ }
63
+
64
+ // Check if we can read the template file:
65
+ foreach ($templates as $file) :
66
+ if ( is_file($file) && is_readable($file) ) :
67
  $tplFileName = $file;
68
  endif;
69
  endforeach;
70
 
71
+ if($tplFileName){
72
  require($tplFileName);
73
+ } else {
74
+ $this->build_output('ul');
75
+ }
76
+ }
77
+
78
+ public static function get_templates($param = null){
79
+ $templates = array();
80
+ $paths = self::getTemplatePaths();
81
+ foreach ($paths as $templatePath) :
82
+ foreach (scandir($templatePath) as $file) :
83
+ // Check that the files found are well formed
84
+ if ( ($file[0] != '.') && (substr($file, -4) == '.php') &&
85
+ is_file($templatePath.$file) && is_readable($templatePath.$file) ) :
86
+ $templateName = substr($file, 0, strlen($file)-4);
87
+ // Add the template only if necessary
88
+ if (!in_array($templateName, $templates)) :
89
+ $templates[] = $templateName;
90
+ endif;
91
+ endif;
92
+ endforeach;
93
+ endforeach;
94
+ return $templates;
95
  }
96
 
97
  private function build_output($tag){
include/ListCategoryPostsWidget.php CHANGED
@@ -32,6 +32,7 @@ class ListCategoryPostsWidget extends WP_Widget{
32
  $thumbnail = ($instance['thumbnail'] == 'on') ? 'yes' : 'no';
33
  $thumbnail_size = ($instance['thumbnail_size']) ? $instance['thumbnail_size'] : 'thumbnail';
34
  $morelink = empty($instance['morelink']) ? ' ' : $instance['morelink'];
 
35
 
36
  $atts = array(
37
  'id' => $category_id,
@@ -51,7 +52,8 @@ class ListCategoryPostsWidget extends WP_Widget{
51
  'catlink' => $showcatlink,
52
  'thumbnail' => $thumbnail,
53
  'thumbnail_size' => $thumbnail_size,
54
- 'morelink' => $morelink
 
55
  );
56
 
57
  echo $before_widget;
@@ -98,6 +100,7 @@ class ListCategoryPostsWidget extends WP_Widget{
98
  $instance['thumbnail'] = strip_tags($new_instance['thumbnail']);
99
  $instance['thumbnail_size'] = strip_tags($new_instance['thumbnail_size']);
100
  $instance['morelink'] = strip_tags($new_instance['morelink']);
 
101
 
102
  return $instance;
103
  }
32
  $thumbnail = ($instance['thumbnail'] == 'on') ? 'yes' : 'no';
33
  $thumbnail_size = ($instance['thumbnail_size']) ? $instance['thumbnail_size'] : 'thumbnail';
34
  $morelink = empty($instance['morelink']) ? ' ' : $instance['morelink'];
35
+ $template = empty($instance['template']) ? 'default' : $instance['template'];
36
 
37
  $atts = array(
38
  'id' => $category_id,
52
  'catlink' => $showcatlink,
53
  'thumbnail' => $thumbnail,
54
  'thumbnail_size' => $thumbnail_size,
55
+ 'morelink' => $morelink,
56
+ 'template' => $template
57
  );
58
 
59
  echo $before_widget;
100
  $instance['thumbnail'] = strip_tags($new_instance['thumbnail']);
101
  $instance['thumbnail_size'] = strip_tags($new_instance['thumbnail_size']);
102
  $instance['morelink'] = strip_tags($new_instance['morelink']);
103
+ $instance['template'] = strip_tags($new_instance['template']);
104
 
105
  return $instance;
106
  }
include/lcp_widget_form.php CHANGED
@@ -20,7 +20,8 @@
20
  'thumbnail_size' =>'',
21
  'offset'=>'',
22
  'show_catlink'=>'',
23
- 'morelink' =>''
 
24
  );
25
  $instance = wp_parse_args( (array) $instance, $default);
26
 
@@ -41,6 +42,7 @@
41
  $thumbnail = strip_tags($instance['thumbnail']);
42
  $thumbnail_size = strip_tags($instance['thumbnail_size']);
43
  $morelink = strip_tags($instance['morelink']);
 
44
 
45
  ?>
46
 
@@ -222,4 +224,27 @@
222
  <input class="widefat" id="<?php echo $this->get_field_id('morelink'); ?>"
223
  name="<?php echo $this->get_field_name('morelink'); ?>" type="text"
224
  value="<?php echo esc_attr($morelink); ?>" />
225
- </p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  'thumbnail_size' =>'',
21
  'offset'=>'',
22
  'show_catlink'=>'',
23
+ 'morelink' =>'',
24
+ 'template' => ''
25
  );
26
  $instance = wp_parse_args( (array) $instance, $default);
27
 
42
  $thumbnail = strip_tags($instance['thumbnail']);
43
  $thumbnail_size = strip_tags($instance['thumbnail_size']);
44
  $morelink = strip_tags($instance['morelink']);
45
+ $template = strip_tags($instance['template']);
46
 
47
  ?>
48
 
224
  <input class="widefat" id="<?php echo $this->get_field_id('morelink'); ?>"
225
  name="<?php echo $this->get_field_name('morelink'); ?>" type="text"
226
  value="<?php echo esc_attr($morelink); ?>" />
227
+ </p>
228
+
229
+ <p>
230
+ <label for="<?php echo $this->get_field_id('template'); ?>">
231
+ <?php _e("Template", 'list-category-posts')?>:
232
+ </label>
233
+ <br/>
234
+ <select id="<?php echo $this->get_field_id('template'); ?>" name="<?php echo $this->get_field_name('template'); ?>">
235
+ <?php
236
+ $templates = CatListDisplayer::get_templates();
237
+ $templates[] = 'default';
238
+ foreach ($templates as $tmp) :
239
+ $option = '<option value="' . $tmp . '" ';
240
+ if ($tmp == $template) :
241
+ $option .= ' selected = "selected" ';
242
+ endif;
243
+ $option .= '">';
244
+ $option .= $tmp;
245
+ $option .= '</option>';
246
+ echo $option;
247
+ endforeach;
248
+ ?>
249
+ </select>
250
+ </p>
list_cat_posts.php CHANGED
@@ -2,8 +2,8 @@
2
  /*
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 from a category into 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, and the number of posts to display. You can use [catlist] as many times as needed with different arguments. Usage: [catlist argument1=value1 argument2=value2].
6
- Version: 0.49.1
7
  Author: Fernando Briano
8
  Author URI: http://picandocodigo.net/
9
 
2
  /*
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, and the number of posts to display. You can use [catlist] as many times as needed with different arguments. Usage: [catlist argument1=value1 argument2=value2].
6
+ Version: 0.50
7
  Author: Fernando Briano
8
  Author URI: http://picandocodigo.net/
9
 
readme.txt CHANGED
@@ -4,12 +4,12 @@ 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: 3.9.1
7
- Stable tag: 0.49.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
  == Description ==
12
- List Category Posts allows you to list posts from a category into a post/page using the [catlist] shortcode. When you're editing a page or post, directly insert the shortcode in your text and the posts will be listed there. The **basic** usage would be something like this:
13
 
14
  `[catlist id=1]`
15
 
@@ -26,10 +26,9 @@ parameters according to what and how you want to show your post's
26
  list:
27
  `[catlist id=1 numberposts=10]`
28
 
29
- There's an options page which only has one option to set for the
30
- plugin at the moment. But new options will be implemented on demand.
31
 
32
- **[Please read the instructions](http://wordpress.org/extend/plugins/list-category-posts/other_notes/)** to learn what parameters are available and how to use them.
33
 
34
  If you want to **List Categories** instead of posts you can use my other plugin **[List categories](http://wordpress.org/plugins/list-categories/)**.
35
 
@@ -220,7 +219,9 @@ update the plugin.
220
 
221
  * **offset** - You can displace or pass over one or more initial posts which would normally be collected by your query through the use of the offset parameter.
222
 
223
- * **content** - Show the full content of the post. If there's a &lt;!--more--&gt; tag in the post, then it will behave just as WordPress does: only show the content previous to the more tag. Default is 'no'. Ex: `[catlist content=yes]`
 
 
224
 
225
  * **catlink** - Show the title of the category with a link to the category. Use the **catlink_string** option to change the link text. Default is 'no'. Ex: `[catlist catlink=yes]`. The way it's programmed, it should only display the title for the first category you chose, and include the posts from all of the categories. I thought of this parameter mostly for using several shortcodes on one page or post, so that each group of posts would have the title of that group's category. If you need to display several titles with posts, you should use one [catlist] shortcode for each category you want to display.
226
 
@@ -421,6 +422,12 @@ Template system has changed. Custom templates should be stored in WordPress them
421
 
422
  == Changelog ==
423
 
 
 
 
 
 
 
424
  = 0.49.1 =
425
 
426
  * Makes sure "starting_with" queries are case insesitive.
4
  Tags: list, categories, posts, cms
5
  Requires at least: 3.3
6
  Tested up to: 3.9.1
7
+ Stable tag: 0.50
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
  == Description ==
12
+ List Category Posts allows you to list posts by category in a post/page using the [catlist] shortcode. When you're editing a page or post, directly insert the shortcode in your text and the posts will be listed there. The **basic** usage would be something like this:
13
 
14
  `[catlist id=1]`
15
 
26
  list:
27
  `[catlist id=1 numberposts=10]`
28
 
29
+ There's an options page with only one option -for the moment-, new options will be implemented on demand.
 
30
 
31
+ **[Please read the instructions](http://wordpress.org/extend/plugins/list-category-posts/other_notes/)** to learn which parameters are available and how to use them.
32
 
33
  If you want to **List Categories** instead of posts you can use my other plugin **[List categories](http://wordpress.org/plugins/list-categories/)**.
34
 
219
 
220
  * **offset** - You can displace or pass over one or more initial posts which would normally be collected by your query through the use of the offset parameter.
221
 
222
+ * **content** - **WARNING**: If you want to show the content on your listed posts, you might want to do this from a new [Page Template](http://codex.wordpress.org/Page_Templates) or a [Custom Post Type](http://codex.wordpress.org/Post_Types#Custom_Post_Type_Templates) template. Using this parameter is discouraged, you can have memory issues as well as infinite loop situations when you're displaying a post that's using List Category Posts. You have been warned. Usage:
223
+
224
+ Show the full content of the post. If there's a &lt;!--more--&gt; tag in the post, then it will behave just as WordPress does: only show the content previous to the more tag. Default is 'no'. Ex: `[catlist content=yes]`
225
 
226
  * **catlink** - Show the title of the category with a link to the category. Use the **catlink_string** option to change the link text. Default is 'no'. Ex: `[catlist catlink=yes]`. The way it's programmed, it should only display the title for the first category you chose, and include the posts from all of the categories. I thought of this parameter mostly for using several shortcodes on one page or post, so that each group of posts would have the title of that group's category. If you need to display several titles with posts, you should use one [catlist] shortcode for each category you want to display.
227
 
422
 
423
  == Changelog ==
424
 
425
+ = 0.50 =
426
+
427
+ * Adds Thai translation by [itpcc](https://github.com/itpcc).
428
+ * The widget can now select an existing template. Thanks [Borjan Tchakaloff](https://github.com/bibz)!
429
+ * Templates code was refactored.
430
+
431
  = 0.49.1 =
432
 
433
  * Makes sure "starting_with" queries are case insesitive.