List category posts - Version 0.25

Version Description

  • Better excerpt
    • Applies title filter, should work with qTranslate
    • Adds post status parameter
    • Adds meta links to plugin page - most importantly: INSTRUCTIONS (please read them).
Download this release

Release Info

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

Code changes from version 0.24 to 0.25

include/CatList.php CHANGED
@@ -1,285 +1,307 @@
1
  <?php
2
- /**
3
- * The CatList object gets the info for the CatListDisplayer to show.
4
- * Each time you use the shortcode, you get an instance of this class.
5
- * @author fernando@picandocodigo.net
6
- */
7
 
8
  class CatList{
9
- private $params = array();
10
- private $lcp_category_id = 0;
11
- private $category_param;
12
-
13
- /**
14
- * Constructor gets the shortcode attributes as parameter
15
- * @param array $atts
16
- */
17
- public function __construct($atts) {
18
- $this->params = $atts;
19
- //Get the category posts:
20
- $this->get_lcp_category();
21
- $this->set_lcp_parameters();
22
- }
23
-
24
- /**
25
- * Order the parameters and query the DB for posts
26
- */
27
- private function set_lcp_parameters(){
28
- $args = array('cat'=> $this->lcp_category_id);
29
-
30
- $args = array_merge($args, array(
31
- 'numberposts' => $this->params['numberposts'],
32
- 'orderby' => $this->params['orderby'],
33
- 'order' => $this->params['order'],
34
- 'offset' => $this->params['offset']
35
- ));
36
-
37
- //Exclude
38
- if(isset($this->params['excludeposts']) && $this->params['excludeposts'] != '0'){
39
- $args['exclude'] = $this->params['excludeposts'];
40
- if (strpos($args['exclude'], 'this') !== FALSE) {
41
- $args['exclude'] = $args['exclude'] . ",". $this->lcp_get_current_post_id();
42
- }
43
- }
44
-
45
- // Post type and post parent:
46
- if(isset($this->params['post_type']) && $this->params['post_type'] != '0'):
47
- $args['post_type'] = $this->params['post_type'];
48
- endif;
49
- if(isset($this->params['post_parent']) && $this->params['post_parent'] != '0'):
50
- $args['post_parent'] = $this->params['post_parent'];
51
- endif;
52
-
53
- // Custom fields 'customfield_name' & 'customfield_value' should both be defined
54
- if( !empty($this->params['customfield_value']) ):
55
- $args['meta_key'] = $this->params['customfield_name'];
56
- $args['meta_value'] = $this->params['customfield_value'];
57
- endif;
58
-
59
- //Get private posts
60
- if(is_user_logged_in()){
61
- $args['post_status'] = array('publish','private');
62
- }
63
-
64
- // Added custom taxonomy support
65
- if ( !empty($this->params['taxonomy']) && !empty($this->params['tags']) ) {
66
- $args['tax_query'] = array(array(
67
- 'taxonomy' => $this->params['taxonomy'],
68
- 'field' => 'slug',
69
- 'terms' => explode(",",$this->params['tags'])
70
- ));
71
- } else if ( !empty($this->params['tags']) ) {
72
- $args['tag'] = $this->params['tags'];
73
- }
74
-
75
- $this->lcp_categories_posts = get_posts($args);
76
- }
77
-
78
-
79
- private function lcp_get_current_post_id(){
80
- global $post;
81
- return $post->ID;
82
- }
83
-
84
-
85
- private function get_lcp_category(){
86
- if ( isset($this->params['categorypage']) && $this->params['categorypage'] == 'yes' ){
87
- $this->lcp_category_id = $this->lcp_get_current_category();
88
- } elseif ( !empty($this->params['name']) ){
89
- if (preg_match('/,/', $this->params['name'])){
90
- $categories = '';
91
- $cat_array = explode(",", $this->params['name']);
92
- foreach ($cat_array as $category) {
93
- $id = $this->get_category_id_by_name($category);
94
- $categories .= $id . ",";
95
- }
96
- $this->lcp_category_id = $categories;
97
- } else {
98
- $this->lcp_category_id = $this->get_category_id_by_name($this->params['name']);
99
- }
100
- } elseif ( isset($this->params['id']) && $this->params['id'] != '0' ){
101
- $this->lcp_category_id = $this->params['id'];
102
- }
103
- }
104
-
105
- public function lcp_get_current_category(){
106
- global $post;
107
- $categories = get_the_category($post->ID);
108
- return $categories[0]->cat_ID;
109
- }
110
-
111
- /**
112
- * Get the category id from its name
113
- * by Eric Celeste / http://eric.clst.org
114
- */
115
- private function get_category_id_by_name($cat_name){
116
- //TODO: Support multiple names (this used to work, but not anymore)
117
- //We check if the name gets the category id, if not, we check the slug.
118
- $term = get_term_by('slug', $cat_name, 'category');
119
- if (!$term):
120
- $term = get_term_by('name', $cat_name, 'category');
121
- endif;
122
-
123
- return ($term) ? $term->term_id : 0;
124
- }
125
-
126
- public function get_category_id(){
127
- return $this->lcp_category_id;
128
- }
129
-
130
- public function get_categories_posts(){
131
- return $this->lcp_categories_posts;
132
- }
133
-
134
- /**
135
- * Load category name and link to the category:
136
- */
137
- public function get_category_link(){
138
- if($this->params['catlink'] == 'yes' && $this->lcp_category_id != 0){
139
- $cat_link = get_category_link($this->lcp_category_id);
140
- $cat_title = get_cat_name($this->lcp_category_id);
141
- return '<a href="' . $cat_link . '" title="' . $cat_title . '">' .
142
- ($this->params['catlink_string'] !== '' ? $this->params['catlink_string'] : $cat_title) . '</a>';
143
- } else {
144
- return null;
145
- }
146
- }
147
-
148
- /**
149
- * Display custom fields.
150
- * @see http://codex.wordpress.org/Function_Reference/get_post_custom
151
- * @param string $custom_key
152
- * @param int $post_id
153
- */
154
- public function get_custom_fields($custom_key, $post_id){
155
- if($this->params['customfield_display'] != ''){
156
- $lcp_customs = '';
157
- //Doesn't work for many when having spaces:
158
- $custom_key = trim($custom_key);
159
- //Create array for many fields:
160
- $custom_array = explode(",", $custom_key);
161
- //Get post custom fields:
162
- $custom_fields = get_post_custom($post_id);
163
- //Loop on custom fields and if there's a value, add it:
164
- foreach ($custom_array as $something){
165
- $my_custom_field = $custom_fields[$something];
166
- if (sizeof($my_custom_field) > 0 ):
167
- foreach ( $my_custom_field as $key => $value ){
168
- $lcp_customs .= "<div class=\"lcp-customfield\">" . $something. " : " . $value . "</div>";
169
- }
170
- endif;
171
- }
172
- return $lcp_customs;
173
- } else {
174
- return null;
175
- }
176
- }
177
-
178
- public function get_comments_count($single){
179
- if (isset($this->params['comments']) && $this->params['comments'] == 'yes'){
180
- return ' (' . $single->comment_count . ')';
181
- } else {
182
- return null;
183
- }
184
- }
185
-
186
- public function get_author_to_show($single){
187
- if ($this->params['author']=='yes'){
188
- $lcp_userdata = get_userdata($single->post_author);
189
- return $lcp_userdata->display_name;
190
- } else {
191
- return null;
192
- }
193
- }
194
-
195
-
196
-
197
- public function get_date_to_show($single){
198
- if ($this->params['date']=='yes'){
199
- //by Verex, great idea!
200
- return get_the_time($this->params['dateformat'], $single);
201
- } else {
202
- return null;
203
- }
204
- }
205
-
206
- public function get_content($single){
207
- if (
208
- isset($this->params['content']) &&
209
- $this->params['content'] =='yes' &&
210
- $single->post_content){
211
- $lcp_content = $single->post_content;
212
- //Need to put some more thought on this!
213
- //Added to stop a post with catlist to display an infinite loop of catlist shortcode parsing
214
- /*if (preg_match("/\[catlist.*\]/", $lcp_content, $regmatch)){
215
- foreach ($regmatch as $match){
216
- $lcp_content = str_replace($match, '(...)',$lcp_content);
217
- }
218
- }*/
219
- // added to parse shortcodes
220
- $lcp_content = apply_filters('the_content', $lcp_content);
221
- $lcp_content = str_replace(']]>', ']]&gt', $lcp_content);
222
- return $lcp_content;
223
- } else {
224
- return null;
225
- }
226
- }
227
-
228
- public function get_excerpt($single){
229
- if (
230
- $this->params['excerpt']=='yes' &&
231
- !($this->params['content']=='yes' &&
232
- $single->post_content) ){
233
- /*
234
- * Strip shortcodes - #5
235
- * http://codex.wordpress.org/Function_Reference/strip_shortcodes
236
- */
237
- if($single->post_excerpt){
238
- return $single->post_excerpt;
239
- }
240
- $lcp_excerpt = strip_shortcodes(strip_tags($single->post_content));
241
- $exc_lim = intval($this->params['excerpt_size']);
242
- $lcp_excerpt = mb_substr($lcp_excerpt, 0, $exc_lim) . '...';
243
- return $lcp_excerpt;
244
- } else {
245
- return null;
246
- }
247
- }
248
-
249
- /**
250
- * Get the post Thumbnail
251
- * @see http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
252
- * @param unknown_type $single
253
- *
254
- */
255
- public function get_thumbnail($single, $lcp_thumb_class = null){
256
- if ($this->params['thumbnail']=='yes'){
257
- $lcp_thumbnail = '';
258
- if ( has_post_thumbnail($single->ID) ) {
259
-
260
- if ( in_array(
261
- $this->params['thumbnail_size'],
262
- array('thumbnail', 'medium', 'large', 'full'))
263
- ) {
264
- $lcp_thumb_size = $this->params['thumbnail_size'];
265
- }elseif ($this->params['thumbnail_size']){
266
- $lcp_thumb_size = explode(",", $this->params['thumbnail_size']);
267
- }else {
268
- $lcp_thumb_size = 'thumbnail';
269
- }//thumbnail size
270
-
271
- $lcp_thumbnail = '<a href="' . get_permalink($single->ID).'">';
272
-
273
- $lcp_thumbnail .= get_the_post_thumbnail(
274
- $single->ID,
275
- $lcp_thumb_size,
276
- ($lcp_thumb_class != null) ? array('class' => $lcp_thumb_class ) : null
277
- );
278
- $lcp_thumbnail .= '</a>';
279
- }
280
- return $lcp_thumbnail;
281
- } else {
282
- return null;
283
- }
284
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
285
  }
1
  <?php
2
+ /**
3
+ * The CatList object gets the info for the CatListDisplayer to show.
4
+ * Each time you use the shortcode, you get an instance of this class.
5
+ * @author fernando@picandocodigo.net
6
+ */
7
 
8
  class CatList{
9
+ private $params = array();
10
+ private $lcp_category_id = 0;
11
+ private $category_param;
12
+
13
+ /**
14
+ * Constructor gets the shortcode attributes as parameter
15
+ * @param array $atts
16
+ */
17
+ public function __construct($atts) {
18
+ $this->params = $atts;
19
+
20
+ //Get the category posts:
21
+ $this->get_lcp_category();
22
+ $this->set_lcp_parameters();
23
+ }
24
+
25
+ /**
26
+ * Order the parameters and query the DB for posts
27
+ */
28
+ private function set_lcp_parameters(){
29
+ $args = array('cat'=> $this->lcp_category_id);
30
+
31
+ $args = array_merge($args, array(
32
+ 'numberposts' => $this->params['numberposts'],
33
+ 'orderby' => $this->params['orderby'],
34
+ 'order' => $this->params['order'],
35
+ 'offset' => $this->params['offset']
36
+ ));
37
+
38
+ //Exclude
39
+ if(isset($this->params['excludeposts']) &&
40
+ $this->params['excludeposts'] != '0'){
41
+ $args['exclude'] = $this->params['excludeposts'];
42
+ if (strpos($args['exclude'], 'this') !== FALSE) :
43
+ $args['exclude'] = $args['exclude'] .
44
+ ",". $this->lcp_get_current_post_id();
45
+ endif;
46
+ }
47
+
48
+ // Post type, status, parent params:
49
+ if(isset($this->params['post_type']) && $this->params['post_type'] != ''):
50
+ $args['post_type'] = $this->params['post_type'];
51
+ endif;
52
+
53
+ if(isset($this->params['post_status']) && $this->params['post_status'] != ''):
54
+ $args['post_status'] = $this->params['post_status'];
55
+ endif;
56
+
57
+
58
+ if(isset($this->params['post_parent']) &&
59
+ $this->params['post_parent'] != '0'):
60
+ $args['post_parent'] = $this->params['post_parent'];
61
+ endif;
62
+
63
+ /*
64
+ * Custom fields 'customfield_name' & 'customfield_value'
65
+ * should both be defined
66
+ */
67
+ if( !empty($this->params['customfield_value']) ):
68
+ $args['meta_key'] = $this->params['customfield_name'];
69
+ $args['meta_value'] = $this->params['customfield_value'];
70
+ endif;
71
+
72
+ //Get private posts
73
+ if(is_user_logged_in()):
74
+ $args['post_status'] = array('publish','private');
75
+ endif;
76
+
77
+ // Added custom taxonomy support
78
+ if ( !empty($this->params['taxonomy']) && !empty($this->params['tags']) ):
79
+ $args['tax_query'] = array(array(
80
+ 'taxonomy' => $this->params['taxonomy'],
81
+ 'field' => 'slug',
82
+ 'terms' => explode(",",$this->params['tags'])
83
+ ));
84
+ elseif ( !empty($this->params['tags']) ):
85
+ $args['tag'] = $this->params['tags'];
86
+ endif;
87
+
88
+ $this->lcp_categories_posts = get_posts($args);
89
+ }
90
+
91
+
92
+ private function lcp_get_current_post_id(){
93
+ global $post;
94
+ return $post->ID;
95
+ }
96
+
97
+
98
+ private function get_lcp_category(){
99
+ if ( isset($this->params['categorypage']) &&
100
+ $this->params['categorypage'] == 'yes' ):
101
+
102
+ $this->lcp_category_id = $this->lcp_get_current_category();
103
+
104
+ elseif ( !empty($this->params['name']) ):
105
+ if (preg_match('/,/', $this->params['name'])):
106
+ $categories = '';
107
+ $cat_array = explode(",", $this->params['name']);
108
+
109
+ foreach ($cat_array as $category) :
110
+ $id = $this->get_category_id_by_name($category);
111
+ $categories .= $id . ",";
112
+ endforeach;
113
+
114
+ $this->lcp_category_id = $categories;
115
+
116
+ else:
117
+ $this->lcp_category_id = $this->get_category_id_by_name($this->params['name']);
118
+ endif;
119
+ elseif ( isset($this->params['id']) && $this->params['id'] != '0' ):
120
+ $this->lcp_category_id = $this->params['id'];
121
+ endif;
122
+ }
123
+
124
+ public function lcp_get_current_category(){
125
+ global $post;
126
+ $categories = get_the_category($post->ID);
127
+ return $categories[0]->cat_ID;
128
+ }
129
+
130
+ /**
131
+ * Get the category id from its name
132
+ * by Eric Celeste / http://eric.clst.org
133
+ */
134
+ private function get_category_id_by_name($cat_name){
135
+ //TODO: Support multiple names (this used to work, but not anymore)
136
+ //We check if the name gets the category id, if not, we check the slug.
137
+ $term = get_term_by('slug', $cat_name, 'category');
138
+ if (!$term):
139
+ $term = get_term_by('name', $cat_name, 'category');
140
+ endif;
141
+
142
+ return ($term) ? $term->term_id : 0;
143
+ }
144
+
145
+ public function get_category_id(){
146
+ return $this->lcp_category_id;
147
+ }
148
+
149
+ public function get_categories_posts(){
150
+ return $this->lcp_categories_posts;
151
+ }
152
+
153
+ /**
154
+ * Load category name and link to the category:
155
+ */
156
+ public function get_category_link(){
157
+ if($this->params['catlink'] == 'yes' && $this->lcp_category_id != 0):
158
+ $cat_link = get_category_link($this->lcp_category_id);
159
+ $cat_title = get_cat_name($this->lcp_category_id);
160
+
161
+ return '<a href="' . $cat_link . '" title="' . $cat_title . '">' .
162
+ ($this->params['catlink_string'] !== '' ? $this->params['catlink_string'] : $cat_title) . '</a>';
163
+ else:
164
+ return null;
165
+ endif;
166
+ }
167
+
168
+ /**
169
+ * Display custom fields.
170
+ * @see http://codex.wordpress.org/Function_Reference/get_post_custom
171
+ * @param string $custom_key
172
+ * @param int $post_id
173
+ */
174
+ public function get_custom_fields($custom_key, $post_id){
175
+ if($this->params['customfield_display'] != ''):
176
+ $lcp_customs = '';
177
+
178
+ //Doesn't work for many when having spaces:
179
+ $custom_key = trim($custom_key);
180
+
181
+ //Create array for many fields:
182
+ $custom_array = explode(",", $custom_key);
183
+
184
+ //Get post custom fields:
185
+ $custom_fields = get_post_custom($post_id);
186
+
187
+ //Loop on custom fields and if there's a value, add it:
188
+ foreach ($custom_array as $something) :
189
+ $my_custom_field = $custom_fields[$something];
190
+ if (sizeof($my_custom_field) > 0 ):
191
+ foreach ( $my_custom_field as $key => $value ) :
192
+ $lcp_customs .= "<div class=\"lcp-customfield\">" .
193
+ $something. " : " . $value . "</div>";
194
+ endforeach;
195
+ endif;
196
+ endforeach;
197
+
198
+ return $lcp_customs;
199
+
200
+ else:
201
+ return null;
202
+ endif;
203
+ }
204
+
205
+ public function get_comments_count($single){
206
+ if (isset($this->params['comments']) &&
207
+ $this->params['comments'] == 'yes'):
208
+ return ' (' . $single->comment_count . ')';
209
+ else:
210
+ return null;
211
+ endif;
212
+ }
213
+
214
+ public function get_author_to_show($single){
215
+ if ($this->params['author']=='yes'):
216
+ $lcp_userdata = get_userdata($single->post_author);
217
+ return $lcp_userdata->display_name;
218
+ else:
219
+ return null;
220
+ endif;
221
+ }
222
+
223
+
224
+
225
+ public function get_date_to_show($single){
226
+ if ($this->params['date']=='yes'):
227
+ //by Verex, great idea!
228
+ return get_the_time($this->params['dateformat'], $single);
229
+ else:
230
+ return null;
231
+ endif;
232
+ }
233
+
234
+ public function get_content($single){
235
+ if (isset($this->params['content']) &&
236
+ $this->params['content'] =='yes' &&
237
+ $single->post_content):
238
+
239
+ $lcp_content = $single->post_content;
240
+ /* Need to put some more thought on this!
241
+ * Added to stop a post with catlist to display an infinite loop of
242
+ * catlist shortcode parsing
243
+ * added to parse shortcodes
244
+ */
245
+ $lcp_content = apply_filters('the_content', $lcp_content);
246
+ $lcp_content = str_replace(']]>', ']]&gt', $lcp_content);
247
+ return $lcp_content;
248
+ else:
249
+ return null;
250
+ endif;
251
+ }
252
+
253
+ public function get_excerpt($single){
254
+ if ($this->params['excerpt']=='yes' &&
255
+ !($this->params['content']=='yes' &&
256
+ $single->post_content) ):
257
+
258
+ if($single->post_excerpt):
259
+ return $single->post_excerpt;
260
+ else:
261
+ $lcp_excerpt = strip_shortcodes(strip_tags($single->post_content));
262
+ $excerpt_length = intval($this->params['excerpt_size']);
263
+ return wp_trim_words($lcp_excerpt, $excerpt_length);
264
+ endif;
265
+ else:
266
+ return null;
267
+ endif;
268
+ }
269
+
270
+ /**
271
+ * Get the post Thumbnail
272
+ * @see http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
273
+ * @param unknown_type $single
274
+ *
275
+ */
276
+ public function get_thumbnail($single, $lcp_thumb_class = null){
277
+ if ($this->params['thumbnail']=='yes'):
278
+ $lcp_thumbnail = '';
279
+ if ( has_post_thumbnail($single->ID) ):
280
+
281
+ if ( in_array( $this->params['thumbnail_size'],
282
+ array('thumbnail', 'medium', 'large', 'full')
283
+ )):
284
+ $lcp_thumb_size = $this->params['thumbnail_size'];
285
+
286
+ elseif ($this->params['thumbnail_size']):
287
+ $lcp_thumb_size = explode(",", $this->params['thumbnail_size']);
288
+ else:
289
+ $lcp_thumb_size = 'thumbnail';
290
+ endif;
291
+
292
+ $lcp_thumbnail = '<a href="' . get_permalink($single->ID).'">';
293
+
294
+ $lcp_thumbnail .= get_the_post_thumbnail(
295
+ $single->ID,
296
+ $lcp_thumb_size,
297
+ ($lcp_thumb_class != null) ? array('class' => $lcp_thumb_class ) : null
298
+ );
299
+ $lcp_thumbnail .= '</a>';
300
+ endif;
301
+ return $lcp_thumbnail;
302
+
303
+ else:
304
+ return null;
305
+ endif;
306
+ }
307
  }
include/CatListDisplayer.php CHANGED
@@ -7,204 +7,206 @@
7
  require_once 'CatList.php';
8
 
9
  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
- }
39
- }
40
- if ( !empty($tplFileName) && is_readable($tplFileName) ) {
41
- require($tplFileName);
42
- }else{
43
- switch($this->params['template']){
44
- case "default":
45
- $this->build_output('ul');
46
- break;
47
- case "div":
48
- $this->build_output('div');
49
- break;
50
- default:
51
- $this->build_output('ul');
52
- break;
53
- }
54
- }
55
- }
56
-
57
- private function build_output($tag){
58
- $this->lcp_output .= $this->get_category_link('strong');
59
- $this->lcp_output .= '<' . $tag;
60
-
61
- //Give a class to wrapper tag
62
- if (isset($this->params['class'])):
63
- $this->lcp_output .= ' class="' . $this->params['class'] . '"';
64
- endif;
65
- $this->lcp_output .= '>';
66
- $inner_tag = ($tag == 'ul') ? 'li' : 'p';
67
-
68
- //Posts loop
69
- foreach ($this->catlist->get_categories_posts() as $single){
70
- if ( !post_password_required($single) ){
71
- $this->lcp_output .= $this->lcp_build_post($single, $inner_tag);
72
- }
73
- }
74
-
75
- //Close wrapper tag
76
- $this->lcp_output .= '</' . $tag . '>';
77
-
78
- if (!empty($this->params['morelink'])):
79
- $href = 'href="' . get_category_link($this->catlist->get_category_id()) . '"';
80
- $class = "";
81
- if (!empty($this->params['morelink_class'])):
82
- $class = 'class="' . $this->params['morelink_class'] . '" ';
83
- endif;
84
- $readmore = $this->params['morelink'];
85
- $this->lcp_output .= '<a ' . $href . ' ' . $class . ' >' . $readmore . '</a>';
86
- endif;
87
- }
88
-
89
- /**
90
- * This function should be overriden for template system.
91
- * @param post $single
92
- * @param HTML tag to display $tag
93
- * @return string
94
- */
95
- private function lcp_build_post($single, $tag){
96
- global $post;
97
- $class ='';
98
- if ( $post->ID == $single->ID ):
99
- $class = " class = current ";
100
- endif;
101
- $lcp_display_output = '<'. $tag . $class . '>';
102
- $lcp_display_output .=
103
- $this->get_post_title($single, $this->params['title_tag'],
104
- $this->params['title_class']);
105
- $lcp_display_output .=
106
- $this->get_comments($single, $this->params['comments_tag'],
107
- $this->params['comments_class']) . ' ';
108
-
109
- $lcp_display_output .=
110
- $this->get_date($single, $this->params['date_tag'],
111
- $this->params['date_class']) . ' ';
112
-
113
- $lcp_display_output .=
114
- $this->get_author($single, $this->params['author_tag'],
115
- $this->params['author_class']) . ' ';
116
-
117
- if (isset($this->params['customfield_display'])){
118
- $lcp_display_output .=
119
- $this->get_custom_fields($this->params['customfield_display'],
120
- $single->ID);
121
- }
122
-
123
- $lcp_display_output .= $this->get_thumbnail($single);
124
-
125
- $lcp_display_output .= $this->get_content($single, $this->params['content_tag'], $this->params['content_class']);
126
-
127
- $lcp_display_output .= $this->get_excerpt($single, $this->params['excerpt_tag'], $this->params['excerpt_class']);;
128
-
129
- $lcp_display_output .= '</' . $tag . '>';
130
-
131
- return $lcp_display_output;
132
- }
133
-
134
- /**
135
- * Auxiliary functions for templates
136
- */
137
- private function get_author($single, $tag = null, $css_class = null){
138
- $info = $this->catlist->get_author_to_show($single);
139
- return $this->assign_style($info, $tag, $css_class);
140
- }
141
-
142
- private function get_comments($single, $tag = null, $css_class = null){
143
- $info = $this->catlist->get_comments_count($single);
144
- return $this->assign_style($info, $tag, $css_class);
145
- }
146
-
147
- private function get_content($single, $tag = null, $css_class = null){
148
- $info = $this->catlist->get_content($single);
149
- return $this->assign_style($info, $tag, $css_class);
150
- }
151
-
152
- private function get_custom_fields($custom_key, $post_id, $tag = null, $css_class = null){
153
- $info = $this->catlist->get_custom_fields($custom_key, $post_id);
154
- return $this->assign_style($info, $tag, $css_class);
155
- }
156
-
157
- private function get_date($single, $tag = null, $css_class = null){
158
- $info = $this->catlist->get_date_to_show($single);
159
- return $this->assign_style($info, $tag, $css_class);
160
- }
161
-
162
- private function get_excerpt($single, $tag = null, $css_class = null){
163
- $info = $this->catlist->get_excerpt($single);
164
- $info = preg_replace('/\[.*\]/', '', $info);
165
- return $this->assign_style($info, $tag, $css_class);
166
- }
167
-
168
- private function get_thumbnail($single, $tag = null){
169
- if ( isset($this->params['thumbnail_class']) &&
170
- $this->params['thumbnail_class'] != '' ){
171
- $lcp_thumb_class = $this->params['thumbnail_class'];
172
- $info = $this->catlist->get_thumbnail($single, $lcp_thumb_class);
173
- } else {
174
- $info = $this->catlist->get_thumbnail($single);
175
- }
176
- return $this->assign_style($info, $tag);
177
- }
178
-
179
- private function get_post_title($single, $tag = null, $css_class = null){
180
- $info = '<a href="' . get_permalink($single->ID) .
181
- '" title="'. $single->post_title . '">' .
182
- $single->post_title . '</a>';
183
- return $this->assign_style($info, $tag, $css_class);
184
- }
185
-
186
- private function get_category_link($tag = null, $css_class = null){
187
- $info = $this->catlist->get_category_link();
188
- return $this->assign_style($info, $tag, $css_class);
189
- }
190
-
191
- /**
192
- * Assign style to the info delivered by CatList. Tag is an HTML tag
193
- * which is passed and will sorround the info. Css_class is the css
194
- * class we want to assign to this tag.
195
- * @param string $info
196
- * @param string $tag
197
- * @param string $css_class
198
- * @return string
199
- */
200
- private function assign_style($info, $tag = null, $css_class = null){
201
- if (!empty($info)){
202
- if (empty($tag)){
203
- return $info;
204
- } elseif (!empty($tag) && empty($css_class)) {
205
- return '<' . $tag . '>' . $info . '</' . $tag . '>';
206
- }
207
- return '<' . $tag . ' class="' . $css_class . '">' . $info . '</' . $tag . '>';
208
- }
209
- }
 
 
210
  }
7
  require_once 'CatList.php';
8
 
9
  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
+ default:
52
+ $this->build_output('ul');
53
+ break;
54
+ endswitch;
55
+ endif;
56
+ }
57
+
58
+ private function build_output($tag){
59
+ $this->lcp_output .= $this->get_category_link('strong');
60
+ $this->lcp_output .= '<' . $tag;
61
+
62
+ //Give a class to wrapper tag
63
+ if (isset($this->params['class'])):
64
+ $this->lcp_output .= ' class="' . $this->params['class'] . '"';
65
+ endif;
66
+ $this->lcp_output .= '>';
67
+ $inner_tag = ($tag == 'ul') ? 'li' : 'p';
68
+
69
+ //Posts loop
70
+ foreach ($this->catlist->get_categories_posts() as $single) :
71
+ if ( !post_password_required($single) ) :
72
+ $this->lcp_output .= $this->lcp_build_post($single, $inner_tag);
73
+ endif;
74
+ endforeach;
75
+
76
+ //Close wrapper tag
77
+ $this->lcp_output .= '</' . $tag . '>';
78
+
79
+ if (!empty($this->params['morelink'])) :
80
+ $href = 'href="' . get_category_link($this->catlist->get_category_id()) . '"';
81
+ $class = "";
82
+ if (!empty($this->params['morelink_class'])) :
83
+ $class = 'class="' . $this->params['morelink_class'] . '" ';
84
+ endif;
85
+ $readmore = $this->params['morelink'];
86
+ $this->lcp_output .= '<a ' . $href . ' ' . $class . ' >' . $readmore . '</a>';
87
+ endif;
88
+ }
89
+
90
+ /**
91
+ * This function should be overriden for template system.
92
+ * @param post $single
93
+ * @param HTML tag to display $tag
94
+ * @return string
95
+ */
96
+ private function lcp_build_post($single, $tag){
97
+ global $post;
98
+ $class ='';
99
+ if ( $post->ID == $single->ID ):
100
+ $class = " class = current ";
101
+ endif;
102
+ $lcp_display_output = '<'. $tag . $class . '>';
103
+ $lcp_display_output .=
104
+ $this->get_post_title($single, $this->params['title_tag'],
105
+ $this->params['title_class']);
106
+ $lcp_display_output .=
107
+ $this->get_comments($single, $this->params['comments_tag'],
108
+ $this->params['comments_class']) . ' ';
109
+
110
+ $lcp_display_output .=
111
+ $this->get_date($single, $this->params['date_tag'],
112
+ $this->params['date_class']) . ' ';
113
+
114
+ $lcp_display_output .=
115
+ $this->get_author($single, $this->params['author_tag'],
116
+ $this->params['author_class']) . ' ';
117
+
118
+ if (isset($this->params['customfield_display'])) :
119
+ $lcp_display_output .=
120
+ $this->get_custom_fields($this->params['customfield_display'],
121
+ $single->ID);
122
+ endif;
123
+
124
+ $lcp_display_output .= $this->get_thumbnail($single);
125
+
126
+ $lcp_display_output .= $this->get_content($single, $this->params['content_tag'], $this->params['content_class']);
127
+
128
+ $lcp_display_output .= $this->get_excerpt($single, $this->params['excerpt_tag'], $this->params['excerpt_class']);;
129
+
130
+ $lcp_display_output .= '</' . $tag . '>';
131
+
132
+ return $lcp_display_output;
133
+ }
134
+
135
+ /**
136
+ * Auxiliary functions for templates
137
+ */
138
+ private function get_author($single, $tag = null, $css_class = null){
139
+ $info = $this->catlist->get_author_to_show($single);
140
+ return $this->assign_style($info, $tag, $css_class);
141
+ }
142
+
143
+ private function get_comments($single, $tag = null, $css_class = null){
144
+ $info = $this->catlist->get_comments_count($single);
145
+ return $this->assign_style($info, $tag, $css_class);
146
+ }
147
+
148
+ private function get_content($single, $tag = null, $css_class = null){
149
+ $info = $this->catlist->get_content($single);
150
+ return $this->assign_style($info, $tag, $css_class);
151
+ }
152
+
153
+ private function get_custom_fields($custom_key, $post_id, $tag = null, $css_class = null){
154
+ $info = $this->catlist->get_custom_fields($custom_key, $post_id);
155
+ return $this->assign_style($info, $tag, $css_class);
156
+ }
157
+
158
+ private function get_date($single, $tag = null, $css_class = null){
159
+ $info = $this->catlist->get_date_to_show($single);
160
+ return $this->assign_style($info, $tag, $css_class);
161
+ }
162
+
163
+ private function get_excerpt($single, $tag = null, $css_class = null){
164
+ $info = $this->catlist->get_excerpt($single);
165
+ $info = preg_replace('/\[.*\]/', '', $info);
166
+ return $this->assign_style($info, $tag, $css_class);
167
+ }
168
+
169
+ private function get_thumbnail($single, $tag = null){
170
+ if ( isset($this->params['thumbnail_class']) &&
171
+ $this->params['thumbnail_class'] != '' ) :
172
+ $lcp_thumb_class = $this->params['thumbnail_class'];
173
+ $info = $this->catlist->get_thumbnail($single, $lcp_thumb_class);
174
+ else:
175
+ $info = $this->catlist->get_thumbnail($single);
176
+ endif;
177
+
178
+ return $this->assign_style($info, $tag);
179
+ }
180
+
181
+ private function get_post_title($single, $tag = null, $css_class = null){
182
+ $info = '<a href="' . get_permalink($single->ID) .
183
+ '" title="'. $single->post_title . '">' .
184
+ apply_filters('the_title', $single->post_title, $single->ID) . '</a>';
185
+ return $this->assign_style($info, $tag, $css_class);
186
+ }
187
+
188
+ private function get_category_link($tag = null, $css_class = null){
189
+ $info = $this->catlist->get_category_link();
190
+ return $this->assign_style($info, $tag, $css_class);
191
+ }
192
+
193
+ /**
194
+ * Assign style to the info delivered by CatList. Tag is an HTML tag
195
+ * which is passed and will sorround the info. Css_class is the css
196
+ * class we want to assign to this tag.
197
+ * @param string $info
198
+ * @param string $tag
199
+ * @param string $css_class
200
+ * @return string
201
+ */
202
+ private function assign_style($info, $tag = null, $css_class = null){
203
+ if (!empty($info)):
204
+ if (empty($tag)):
205
+ return $info;
206
+ elseif (!empty($tag) && empty($css_class)) :
207
+ return '<' . $tag . '>' . $info . '</' . $tag . '>';
208
+ endif;
209
+ return '<' . $tag . ' class="' . $css_class . '">' . $info . '</' . $tag . '>';
210
+ endif;
211
+ }
212
  }
include/ListCategoryPostsWidget.php CHANGED
@@ -7,90 +7,90 @@ require_once 'CatListDisplayer.php';
7
 
8
  class ListCategoryPostsWidget extends WP_Widget{
9
 
10
- function ListCategoryPostsWidget() {
11
- $opts = array('description' => 'List posts from a specified category');
12
- parent::WP_Widget(false, $name = 'List Category Posts', $opts);
13
- }
14
 
15
- function widget($args, $instance) {
16
- extract( $args );
17
- $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
18
- $limit = (is_numeric($instance['limit'])) ? $instance['limit'] : 5;
19
- $orderby = ($instance['orderby']) ? $instance['orderby'] : 'date';
20
- $order = ($instance['order']) ? $instance['order'] : 'desc';
21
- $exclude = ($instance['exclude'] != '') ? $instance['exclude'] : 0;
22
- $excludeposts = ($instance['excludeposts'] != '') ? $instance['excludeposts'] : 0;
23
- $offset = (is_numeric($instance['offset'])) ? $instance['offset'] : 0;
24
- $category_id = $instance['categoryid'];
25
- $dateformat = ($instance['dateformat']) ? $instance['dateformat'] : get_option('date_format');
26
- $showdate = ($instance['show_date'] == 'on') ? 'yes' : 'no';
27
- $showexcerpt = ($instance['show_excerpt'] == 'on') ? 'yes' : 'no';
28
- $showauthor = ($instance['show_author'] == 'on') ? 'yes' : 'no';
29
- $showcatlink = ($instance['show_catlink'] == 'on') ? 'yes' : 'no';
30
- $thumbnail = ($instance['thumbnail'] == 'on') ? 'yes' : 'no';
31
- $thumbnail_size = ($instance['thumbnail_size']) ? $instance['thumbnail_size'] : 'thumbnail';
32
- $morelink = empty($instance['morelink']) ? ' ' : $instance['morelink'];
33
 
34
- echo $before_widget;
35
- echo $before_title . $title . $after_title;
36
 
37
- $atts = array(
38
- 'id' => $category_id,
39
- 'orderby' => $orderby,
40
- 'order' => $order,
41
- 'numberposts' => $limit,
42
- 'date' => $showdate,
43
- 'author' => $showauthor,
44
- 'dateformat' => $dateformat,
45
- 'template' => 'default',
46
- 'excerpt' => $showexcerpt,
47
- 'exclude' => $exclude,
48
- 'excludeposts' => $excludeposts,
49
- 'offset' => $offset,
50
- 'catlink' => $showcatlink,
51
- 'thumbnail' => $thumbnail,
52
- 'thumbnail_size' => $thumbnail_size,
53
- 'morelink' => $morelink
54
- );
55
-
56
- $catlist_displayer = new CatListDisplayer($atts);
57
- echo $catlist_displayer->display();
58
- echo $after_widget;
59
- }
60
 
61
- /** @see WP_Widget::update */
62
- function update($new_instance, $old_instance) {
63
- $instance = $old_instance;
64
- $instance['title'] = strip_tags($new_instance['title']);
65
- $instance['limit'] = strip_tags($new_instance['limit']);
66
- $instance['orderby'] = strip_tags($new_instance['orderby']);
67
- $instance['order'] = strip_tags($new_instance['order']);
68
- $instance['exclude'] = strip_tags($new_instance['exclude']);
69
- $instance['excludeposts'] = strip_tags($new_instance['excludeposts']);
70
- $instance['offset'] = strip_tags($new_instance['offset']);
71
- $instance['categoryid'] = strip_tags($new_instance['categoryid']);
72
- $instance['dateformat'] = strip_tags($new_instance['dateformat']);
73
- $instance['show_date'] = strip_tags($new_instance['show_date']);
74
- $instance['show_excerpt'] = strip_tags($new_instance['show_excerpt']);
75
- $instance['show_author'] = strip_tags($new_instance['show_author']);
76
- $instance['show_catlink'] = strip_tags($new_instance['show_catlink']);
77
- $instance['show_catlink'] = strip_tags($new_instance['show_catlink']);
78
- $instance['thumbnail'] = strip_tags($new_instance['thumbnail']);
79
- $instance['thumbnail_size'] = strip_tags($new_instance['thumbnail_size']);
80
- $instance['morelink'] = strip_tags($new_instance['morelink']);
81
 
82
- return $instance;
83
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
 
85
- /** @see WP_Widget::form */
86
- function form($instance) {
87
- include('lcp_widget_form.php');
88
- }
 
 
 
89
  }
90
 
91
  add_action('widgets_init', create_function('', 'return register_widget("listCategoryPostsWidget");'));
92
 
93
- #Working on i18n, if you want to give a hand visit: http://wordpress.stackexchange.com/questions/32339/widget-translation-on-my-plugin
94
- #$translation_dir = '../languages';
95
- #load_plugin_textdomain( 'list-category-posts', null, $translation_dir );
96
  ?>
7
 
8
  class ListCategoryPostsWidget extends WP_Widget{
9
 
10
+ function ListCategoryPostsWidget() {
11
+ $opts = array('description' => 'List posts from a specified category');
12
+ parent::WP_Widget(false, $name = 'List Category Posts', $opts);
13
+ }
14
 
15
+ function widget($args, $instance) {
16
+ extract( $args );
17
+ $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
18
+ $limit = (is_numeric($instance['limit'])) ? $instance['limit'] : 5;
19
+ $orderby = ($instance['orderby']) ? $instance['orderby'] : 'date';
20
+ $order = ($instance['order']) ? $instance['order'] : 'desc';
21
+ $exclude = ($instance['exclude'] != '') ? $instance['exclude'] : 0;
22
+ $excludeposts = ($instance['excludeposts'] != '') ? $instance['excludeposts'] : 0;
23
+ $offset = (is_numeric($instance['offset'])) ? $instance['offset'] : 0;
24
+ $category_id = $instance['categoryid'];
25
+ $dateformat = ($instance['dateformat']) ? $instance['dateformat'] : get_option('date_format');
26
+ $showdate = ($instance['show_date'] == 'on') ? 'yes' : 'no';
27
+ $showexcerpt = ($instance['show_excerpt'] == 'on') ? 'yes' : 'no';
28
+ $showauthor = ($instance['show_author'] == 'on') ? 'yes' : 'no';
29
+ $showcatlink = ($instance['show_catlink'] == 'on') ? 'yes' : 'no';
30
+ $thumbnail = ($instance['thumbnail'] == 'on') ? 'yes' : 'no';
31
+ $thumbnail_size = ($instance['thumbnail_size']) ? $instance['thumbnail_size'] : 'thumbnail';
32
+ $morelink = empty($instance['morelink']) ? ' ' : $instance['morelink'];
33
 
34
+ echo $before_widget;
35
+ echo $before_title . $title . $after_title;
36
 
37
+ $atts = array(
38
+ 'id' => $category_id,
39
+ 'orderby' => $orderby,
40
+ 'order' => $order,
41
+ 'numberposts' => $limit,
42
+ 'date' => $showdate,
43
+ 'author' => $showauthor,
44
+ 'dateformat' => $dateformat,
45
+ 'template' => 'default',
46
+ 'excerpt' => $showexcerpt,
47
+ 'exclude' => $exclude,
48
+ 'excludeposts' => $excludeposts,
49
+ 'offset' => $offset,
50
+ 'catlink' => $showcatlink,
51
+ 'thumbnail' => $thumbnail,
52
+ 'thumbnail_size' => $thumbnail_size,
53
+ 'morelink' => $morelink
54
+ );
 
 
 
 
 
55
 
56
+ $catlist_displayer = new CatListDisplayer($atts);
57
+ echo $catlist_displayer->display();
58
+ echo $after_widget;
59
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
 
61
+ /** @see WP_Widget::update */
62
+ function update($new_instance, $old_instance) {
63
+ $instance = $old_instance;
64
+ $instance['title'] = strip_tags($new_instance['title']);
65
+ $instance['limit'] = strip_tags($new_instance['limit']);
66
+ $instance['orderby'] = strip_tags($new_instance['orderby']);
67
+ $instance['order'] = strip_tags($new_instance['order']);
68
+ $instance['exclude'] = strip_tags($new_instance['exclude']);
69
+ $instance['excludeposts'] = strip_tags($new_instance['excludeposts']);
70
+ $instance['offset'] = strip_tags($new_instance['offset']);
71
+ $instance['categoryid'] = strip_tags($new_instance['categoryid']);
72
+ $instance['dateformat'] = strip_tags($new_instance['dateformat']);
73
+ $instance['show_date'] = strip_tags($new_instance['show_date']);
74
+ $instance['show_excerpt'] = strip_tags($new_instance['show_excerpt']);
75
+ $instance['show_author'] = strip_tags($new_instance['show_author']);
76
+ $instance['show_catlink'] = strip_tags($new_instance['show_catlink']);
77
+ $instance['show_catlink'] = strip_tags($new_instance['show_catlink']);
78
+ $instance['thumbnail'] = strip_tags($new_instance['thumbnail']);
79
+ $instance['thumbnail_size'] = strip_tags($new_instance['thumbnail_size']);
80
+ $instance['morelink'] = strip_tags($new_instance['morelink']);
81
 
82
+ return $instance;
83
+ }
84
+
85
+ /** @see WP_Widget::form */
86
+ function form($instance) {
87
+ include('lcp_widget_form.php');
88
+ }
89
  }
90
 
91
  add_action('widgets_init', create_function('', 'return register_widget("listCategoryPostsWidget");'));
92
 
93
+ # Working on i18n, if you want to give a hand visit: http://wordpress.stackexchange.com/questions/32339/widget-translation-on-my-plugin
94
+ # $translation_dir = '../languages';
95
+ # load_plugin_textdomain( 'list-category-posts', null, $translation_dir );
96
  ?>
list_cat_posts.php CHANGED
@@ -1,97 +1,115 @@
1
  <?php
2
- /*
3
- Plugin Name: List category posts
4
- Plugin URI: http://picandocodigo.net/programacion/wordpress/list-category-posts-wordpress-plugin-english/
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.24
7
- Author: Fernando Briano
8
- Author URI: http://picandocodigo.net/
9
- */
10
 
11
- /* Copyright 2008-2011 Fernando Briano (email : fernando@picandocodigo.net)
12
 
13
- This program is free software; you can redistribute it and/or modify
14
- it under the terms of the GNU General Public License as published by
15
- the Free Software Foundation; either version 3 of the License, or
16
- any later version.
17
 
18
- This program is distributed in the hope that it will be useful,
19
- but WITHOUT ANY WARRANTY; without even the implied warranty of
20
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
- GNU General Public License for more details.
22
 
23
- You should have received a copy of the GNU General Public License
24
- along with this program; if not, write to the Free Software
25
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
- */
27
 
28
  include 'include/ListCategoryPostsWidget.php';
29
  require_once 'include/CatListDisplayer.php';
30
 
31
  class ListCategoryPosts{
32
- /**
33
- * Gets the shortcode parameters and instantiate plugin objects
34
- * @param $atts
35
- * @param $content
36
- */
37
- function catlist_func($atts, $content = null) {
38
- $atts = shortcode_atts(array(
39
- 'id' => '0',
40
- 'name' => '',
41
- 'orderby' => 'date',
42
- 'order' => 'desc',
43
- 'numberposts' => '5',
44
- 'date' => 'no',
45
- 'date_tag' => '',
46
- 'date_class' =>'',
47
- 'dateformat' => get_option('date_format'),
48
- 'author' => 'no',
49
- 'author_tag' =>'',
50
- 'author_class' => '',
51
- 'template' => 'default',
52
- 'excerpt' => 'no',
53
- 'excerpt_size' => '255',
54
- 'excerpt_tag' =>'',
55
- 'excerpt_class' =>'',
56
- 'exclude' => '0',
57
- 'excludeposts' => '0',
58
- 'offset' => '0',
59
- 'tags' => '',
60
- 'content' => 'no',
61
- 'content_tag' => '',
62
- 'content_class' => '',
63
- 'catlink' => 'no',
64
- 'catlink_string' => '',
65
- 'catlink_tag' =>'',
66
- 'catlink_class' => '',
67
- 'comments' => 'no',
68
- 'comments_tag' => '',
69
- 'comments_class' => '',
70
- 'thumbnail' => 'no',
71
- 'thumbnail_size' => 'thumbnail',
72
- 'thumbnail_class' => '',
73
- 'title_tag' => '',
74
- 'title_class' => '',
75
- 'post_type' => '',
76
- 'post_parent' => '0',
77
- 'class' => 'lcp_catlist',
78
- 'customfield_name' => '',
79
- 'customfield_value' =>'',
80
- 'customfield_display' =>'',
81
- 'taxonomy' => '',
82
- 'categorypage' => '',
83
- 'morelink' => '',
84
- 'morelink_class' => ''
85
- ), $atts);
86
-
87
- $catlist_displayer = new CatListDisplayer($atts);
88
- return $catlist_displayer->display();
89
- }
90
 
 
 
 
91
  }
92
 
93
  add_shortcode( 'catlist', array('ListCategoryPosts', 'catlist_func') );
94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  /**
96
  * TO-DO:
97
  Add Older Posts at bottom of List Category Post page
1
  <?php
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.25
7
+ Author: Fernando Briano
8
+ Author URI: http://picandocodigo.net/
9
+ */
10
 
11
+ /* Copyright 2008-2011 Fernando Briano (email : fernando@picandocodigo.net)
12
 
13
+ This program is free software; you can redistribute it and/or modify
14
+ it under the terms of the GNU General Public License as published by
15
+ the Free Software Foundation; either version 3 of the License, or
16
+ any later version.
17
 
18
+ This program is distributed in the hope that it will be useful,
19
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ GNU General Public License for more details.
22
 
23
+ You should have received a copy of the GNU General Public License
24
+ along with this program; if not, write to the Free Software
25
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
+ */
27
 
28
  include 'include/ListCategoryPostsWidget.php';
29
  require_once 'include/CatListDisplayer.php';
30
 
31
  class ListCategoryPosts{
32
+ /**
33
+ * Gets the shortcode parameters and instantiate plugin objects
34
+ * @param $atts
35
+ * @param $content
36
+ */
37
+ function catlist_func($atts, $content = null) {
38
+ $atts = shortcode_atts(array(
39
+ 'id' => '0',
40
+ 'name' => '',
41
+ 'orderby' => 'date',
42
+ 'order' => 'desc',
43
+ 'numberposts' => '5',
44
+ 'date' => 'no',
45
+ 'date_tag' => '',
46
+ 'date_class' =>'',
47
+ 'dateformat' => get_option('date_format'),
48
+ 'author' => 'no',
49
+ 'author_tag' =>'',
50
+ 'author_class' => '',
51
+ 'template' => 'default',
52
+ 'excerpt' => 'no',
53
+ 'excerpt_size' => '255',
54
+ 'excerpt_tag' =>'',
55
+ 'excerpt_class' =>'',
56
+ 'exclude' => '0',
57
+ 'excludeposts' => '0',
58
+ 'offset' => '0',
59
+ 'tags' => '',
60
+ 'content' => 'no',
61
+ 'content_tag' => '',
62
+ 'content_class' => '',
63
+ 'catlink' => 'no',
64
+ 'catlink_string' => '',
65
+ 'catlink_tag' =>'',
66
+ 'catlink_class' => '',
67
+ 'comments' => 'no',
68
+ 'comments_tag' => '',
69
+ 'comments_class' => '',
70
+ 'thumbnail' => 'no',
71
+ 'thumbnail_size' => 'thumbnail',
72
+ 'thumbnail_class' => '',
73
+ 'title_tag' => '',
74
+ 'title_class' => '',
75
+ 'post_type' => '',
76
+ 'post_status' => '',
77
+ 'post_parent' => '0',
78
+ 'class' => 'lcp_catlist',
79
+ 'customfield_name' => '',
80
+ 'customfield_value' =>'',
81
+ 'customfield_display' =>'',
82
+ 'taxonomy' => '',
83
+ 'categorypage' => '',
84
+ 'morelink' => '',
85
+ 'morelink_class' => ''
86
+ ), $atts);
 
 
 
87
 
88
+ $catlist_displayer = new CatListDisplayer($atts);
89
+ return $catlist_displayer->display();
90
+ }
91
  }
92
 
93
  add_shortcode( 'catlist', array('ListCategoryPosts', 'catlist_func') );
94
 
95
+
96
+ function lpc_meta($links, $file) {
97
+ $plugin = plugin_basename(__FILE__);
98
+
99
+ if ($file == $plugin):
100
+ return array_merge(
101
+ $links,
102
+ array( sprintf('<a href="http://wordpress.org/extend/plugins/list-category-posts/other_notes/">%s</a>', __('How to use')) ),
103
+ array( sprintf('<a href="http://picandocodigo.net/programacion/wordpress/list-category-posts-wordpress-plugin-english/#support">%s</a>', __('Donate')) ),
104
+ array( sprintf('<a href="https://github.com/picandocodigo/List-Category-Posts">%s</a>', __('Fork on Github')) )
105
+ );
106
+ endif;
107
+
108
+ return $links;
109
+ }
110
+
111
+ add_filter( 'plugin_row_meta', 'lpc_meta', 10, 2 );
112
+
113
  /**
114
  * TO-DO:
115
  Add Older Posts at bottom of List Category Post page
readme.txt CHANGED
@@ -3,15 +3,15 @@ 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: 2.8
6
- Tested up to: 3.3.1
7
- Stable tag: 0.24
8
 
9
  == Description ==
10
  List Category Posts allows you to list posts from a category into a post/page using the [catlist] shortcode.
11
 
12
  The 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 also display the post author, date, excerpt, custom field values, even the content! The [catlist] shortcode can be used as many times as needed with different arguments on each post/page.
13
 
14
- **New feature**: The different elements to display con now be styled with CSS. you can define an HTML tag to wrap the element with, and a CSS class for this tag. Check [Other Notes](http://wordpress.org/extend/plugins/list-category-posts/other_notes/) for usage.
15
 
16
  Great to use WordPress as a CMS, and create pages with several categories posts.
17
 
@@ -43,6 +43,8 @@ I've moved the development to [GitHub](https://github.com/picandocodigo/List-Cat
43
 
44
  ==Other notes==
45
 
 
 
46
  **Selecting the category**
47
 
48
  The plugin can figure out the category from which you want to list posts in three different ways: Using the *category id*, the *category name or slug* and *detecting the current post's category*.
@@ -58,9 +60,9 @@ You can use the *categorypage* parameter to make it detect the category id of th
58
 
59
  **Other parameters**
60
 
61
- * **tags** - Tag support, you can display posts from a certain tag.
62
 
63
- * **orderby** - To customize the order. Valid values are:
64
  * **author** - Sort by the numeric author IDs.
65
  * **category** - Sort by the numeric category IDs.
66
  * **content** - Sort by content.
@@ -111,6 +113,18 @@ You can use the *categorypage* parameter to make it detect the category id of th
111
 
112
  * **post_type** - The type of post to show. Available options are: post - Default, page, attachment, any - all post types.
113
 
 
 
 
 
 
 
 
 
 
 
 
 
114
  * **post_parent** - Show only the children of the post with this ID. Default: None.
115
 
116
  * **class** - CSS class for the default UL generated by the plugin.
@@ -166,6 +180,8 @@ You can have as many different templates as you want, and use them in different
166
  Please check:
167
  http://wordpress.stackexchange.com/questions/9338/list-category-posts-plugin-upgrade-fails-fatal-error/9340#9340
168
 
 
 
169
  == Upgrade Notice ==
170
 
171
  = 0.18 =
@@ -188,6 +204,13 @@ Template system has changed. Custom templates should be stored in WordPress them
188
 
189
  == Changelog ==
190
 
 
 
 
 
 
 
 
191
  = 0.24 =
192
 
193
  * Fixes "excerpt doesn't strip shortcodes" - https://github.com/picandocodigo/List-Category-Posts/issues/5
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: 2.8
6
+ Tested up to: 3.5
7
+ Stable tag: 0.25
8
 
9
  == Description ==
10
  List Category Posts allows you to list posts from a category into a post/page using the [catlist] shortcode.
11
 
12
  The 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 also display the post author, date, excerpt, custom field values, even the content! The [catlist] shortcode can be used as many times as needed with different arguments on each post/page.
13
 
14
+ **Customization**: The different elements to display con be styled with CSS. you can define an HTML tag to wrap the element with, and a CSS class for this tag. Check [Other Notes](http://wordpress.org/extend/plugins/list-category-posts/other_notes/) for usage.
15
 
16
  Great to use WordPress as a CMS, and create pages with several categories posts.
17
 
43
 
44
  ==Other notes==
45
 
46
+ = INSTRUCTIONS: How to use the plugin =
47
+
48
  **Selecting the category**
49
 
50
  The plugin can figure out the category from which you want to list posts in three different ways: Using the *category id*, the *category name or slug* and *detecting the current post's category*.
60
 
61
  **Other parameters**
62
 
63
+ * **tags** - Tag support, you can display posts from a certain tag.
64
 
65
+ * **orderby** - To customize the order. Valid values are:
66
  * **author** - Sort by the numeric author IDs.
67
  * **category** - Sort by the numeric category IDs.
68
  * **content** - Sort by content.
113
 
114
  * **post_type** - The type of post to show. Available options are: post - Default, page, attachment, any - all post types.
115
 
116
+ * **post_status** - use post status, default value is 'publish'. Valid values:
117
+ * 'publish' - a published post or page.
118
+ * 'pending' - post is pending review.
119
+ * 'draft' - a post in draft status.
120
+ * 'auto-draft' - a newly created post, with no content.
121
+ * 'future' - a post to publish in the future.
122
+ * 'private' - not visible to users who are not logged in.
123
+ * 'inherit' - a revision. see get_children.
124
+ * 'trash' - post is in trashbin (available with Version 2.9).
125
+ * 'any' - retrieves any status except those from post types with 'exclude_from_search' set to true.
126
+
127
+
128
  * **post_parent** - Show only the children of the post with this ID. Default: None.
129
 
130
  * **class** - CSS class for the default UL generated by the plugin.
180
  Please check:
181
  http://wordpress.stackexchange.com/questions/9338/list-category-posts-plugin-upgrade-fails-fatal-error/9340#9340
182
 
183
+ **Please do not ask for support when you are having issues with your CSS**. I can't solve every user's CSS problems. Feel free to ask on the forums or WP Answers. But please, **[read the instructions first](http://wordpress.org/extend/plugins/list-category-posts/other_notes/)**.
184
+
185
  == Upgrade Notice ==
186
 
187
  = 0.18 =
204
 
205
  == Changelog ==
206
 
207
+ = 0.25 =
208
+
209
+ * Better excerpt
210
+ * Applies title filter, should work with qTranslate
211
+ * Adds post status parameter
212
+ * Adds meta links to plugin page - most importantly: INSTRUCTIONS (please read them).
213
+
214
  = 0.24 =
215
 
216
  * Fixes "excerpt doesn't strip shortcodes" - https://github.com/picandocodigo/List-Category-Posts/issues/5