List category posts - Version 0.17

Version Description

Upgrade your templates: Templates system was rewritten, so your current templates will probably not work. Check out the new default.php file on /templates to see the simpler new way to work with templates.

Download this release

Release Info

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

Code changes from version 0.16.1 to 0.17

include/CatList.php ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * The CatList object gets the info for the CatListDisplayer to show.
4
+ * Each shortcode appearence is an instance of this class.
5
+ * @author fernando@picandocodigo.nets
6
+ */
7
+
8
+ class CatList{
9
+ private $params = array();
10
+ private $lcp_categories_posts = array();
11
+ private $lcp_category_id = 0;
12
+ private $lcp_category_name = '';
13
+
14
+ /**
15
+ * Constructor gets the shortcode attributes as parameter
16
+ * @param array $atts
17
+ */
18
+ public function __construct($atts) {
19
+ $this->params = $atts;
20
+ //Get the category posts:
21
+ $this->lcp_set_categories();
22
+ }
23
+
24
+ /**
25
+ * Get the categories & posts
26
+ */
27
+ private function lcp_set_categories(){
28
+ if($this->params['name'] != '' && $this->params['id'] == '0'){
29
+ $this->lcp_category_name = $this->params['name'];
30
+ $lcp_category = 'category_name=' . $this->lcp_category_name;
31
+ //$this->lcp_category_id = ;
32
+ }else{
33
+ $this->lcp_category_id = $this->params['id'];
34
+ $lcp_category = 'cat=' . $this->lcp_category_id;
35
+ }
36
+
37
+ //Build the query for get_posts()
38
+ $lcp_query = $lcp_category.'&numberposts=' . $this->params['numberposts'] .
39
+ '&orderby=' . $this->params['orderby'] .
40
+ '&order=' . $this->params['order'] .
41
+ '&exclude=' . $this->params['excludeposts'] .
42
+ '&tag=' . $this->params['tags'] .
43
+ '&offset=' . $this->params['offset'];
44
+
45
+ // Post type and post parent:
46
+ if($this->params['post_type']): $lcp_query .= '&post_type=' . $this->params['post_type']; endif;
47
+ if($this->params['post_parent']): $lcp_query .= '&post_parent=' . $this->params['post_parent']; endif;
48
+
49
+ // Custom fields 'customfield_name' & 'customfield_value' should both be defined
50
+ if($this->params['customfield_name']!='' && $this->params['customfield_value'] != ''):
51
+ $lcp_query .= '&meta_key=' . $this->params['customfield_name'] . '&meta_value=' . $this->params['customfield_value'];
52
+ endif;
53
+ $this->lcp_categories_posts = get_posts($lcp_query);
54
+ }
55
+
56
+ public function get_categories_posts(){
57
+ return $this->lcp_categories_posts;
58
+ }
59
+
60
+ /**
61
+ * Load category name and link to the category:
62
+ */
63
+ public function get_category_link(){
64
+ $cat_link = get_category_link($this->lcp_category_id);
65
+ $cat_title = get_cat_name($this->lcp_category_id);
66
+ return '<a href="' . $cat_link . '" title="' . $cat_title . '">' . $cat_title . '</a>';
67
+ }
68
+
69
+ /**
70
+ * Display custom fields.
71
+ * @see http://codex.wordpress.org/Function_Reference/get_post_custom
72
+ * @param string $custom_key
73
+ * @param int $post_id
74
+ */
75
+ public function get_custom_fields($custom_key, $post_id){
76
+ if($this->params['customfield_display'] != ''){
77
+ $lcp_customs = '';
78
+ //Doesn't work for many when having spaces:
79
+ $custom_key = trim($custom_key);
80
+ //Create array for many fields:
81
+ $custom_array = explode(",", $custom_key);
82
+ //Get post custom fields:
83
+ $custom_fields = get_post_custom($post_id);
84
+ //Loop on custom fields and if there's a value, add it:
85
+ foreach ($custom_array as $something){
86
+ $my_custom_field = $custom_fields[$something];
87
+ if (sizeof($my_custom_field) > 0 ):
88
+ foreach ( $my_custom_field as $key => $value ){
89
+ $lcp_customs .= "<div class=\"lcp-customfield\">" . $something. " : " . $value . "</div>";
90
+ }
91
+ endif;
92
+ }
93
+ return $lcp_customs;
94
+ }
95
+ }
96
+
97
+ public function get_comments_count($single){
98
+ if ($this->params['comments'] == 'yes'){
99
+ return ' (' . $single->comment_count . ')';
100
+ }
101
+ }
102
+
103
+ public function get_author_to_show($single){
104
+ if ($this->params['author']=='yes'){
105
+ $lcp_userdata = get_userdata($single->post_author);
106
+ return $lcp_userdata->display_name;
107
+ }
108
+ }
109
+
110
+
111
+
112
+ public function get_date_to_show($single){
113
+ if ($this->params['date']=='yes'){
114
+ //by Verex, great idea!
115
+ return get_the_time($this->params['dateformat'], $single);
116
+ }
117
+ }
118
+
119
+ public function get_content($single){
120
+ if ($this->params['content']=='yes' && $single->post_content){
121
+ $lcp_content = $single->post_content;
122
+ //Need to put some more thought on this!
123
+ //Added to stop a post with catlist to display an infinite loop of catlist shortcode parsing
124
+ /*if (preg_match("/\[catlist.*\]/", $lcp_content, $regmatch)){
125
+ foreach ($regmatch as $match){
126
+ $lcp_content = str_replace($match, '(...)',$lcp_content);
127
+ }
128
+ }*/
129
+ $lcp_content = apply_filters('the_content', $lcp_content); // added to parse shortcodes
130
+ $lcp_content = str_replace(']]>', ']]&gt', $lcp_content); // added to parse shortcodes
131
+ return $lcp_content;
132
+ }
133
+ }
134
+
135
+ public function get_excerpt($single){
136
+ if ($this->params['excerpt']=='yes' && !($this->params['content']=='yes' && $single->post_content) ){
137
+ if($single->post_excerpt){
138
+ return $single->post_excerpt;
139
+ }
140
+ $lcp_excerpt = strip_tags($single->post_content);
141
+ if ( post_password_required($single) ) {
142
+ $lcp_excerpt = __('There is no excerpt because this is a protected post.');
143
+ return $lcp_excerpt;
144
+ }
145
+ if (strlen($lcp_excerpt) > 255) {
146
+ $lcp_excerpt = substr($lcp_excerpt, 0, 252) . '...';
147
+ }
148
+ return $lcp_excerpt;
149
+ }
150
+ }
151
+
152
+ /**
153
+ * Get the post Thumbnail
154
+ * @see http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
155
+ * @param unknown_type $single
156
+ */
157
+ public function get_thumbnail($single){
158
+ if ($this->params['thumbnail']=='yes'){
159
+ $lcp_thumbnail = '';
160
+ if ( has_post_thumbnail($single->ID) ) {
161
+ $lcp_thumbnail = get_the_post_thumbnail($single->ID);
162
+ }
163
+ return $lcp_thumbnail;
164
+ }
165
+ }
166
+
167
+
168
+ }
include/CatListDisplayer.php ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This is an auxiliary class to help display the info on your CatList.php instance.
4
+ *
5
+ * @author fernando@picandocodigo.nets
6
+ */
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 .= '<' . $tag . ' class="'.$this->params['class'].'">';
59
+ $inner_tag = ($tag == 'ul') ? 'li' : 'p';
60
+ //Posts loop
61
+ foreach ($this->catlist->get_categories_posts() as $single):
62
+ $this->lcp_output .= $this->lcp_build_post($single, $inner_tag);
63
+ endforeach;
64
+
65
+ $this->lcp_output .= '</' . $tag . '>';
66
+ }
67
+
68
+ /**
69
+ * This function should be overriden for template system.
70
+ * @param post $single
71
+ * @param HTML tag to display $tag
72
+ * @return string
73
+ */
74
+ private function lcp_build_post($single, $tag){
75
+ $lcp_display_output = '<'. $tag . '>' . $this->get_post_title($single);
76
+
77
+ $lcp_display_output .= $this->get_comments($single);
78
+
79
+ $lcp_display_output .= ' ' . $this->get_date($single);
80
+
81
+ $lcp_display_output .= '<br/>' . __('Author') . ': ' . $this->get_author($single) . '<br/>';
82
+
83
+ $lcp_display_output .= $this->get_custom_fields($this->params['customfield_display'], $single->ID);
84
+
85
+ $lcp_display_output .= $this->get_thumbnail($single);
86
+
87
+ $lcp_display_output .= $this->get_content($single);
88
+
89
+ $lcp_display_output .= $this->get_excerpt($single);
90
+
91
+ $lcp_display_output .= '</' . $tag . '>';
92
+
93
+ return $lcp_display_output;
94
+ }
95
+
96
+ /**
97
+ * Auxiliary functions for templates
98
+ */
99
+ private function get_author($single){
100
+ return $this->catlist->get_author_to_show($single);
101
+ }
102
+
103
+ private function get_comments($single){
104
+ return $this->catlist->get_comments_count($single);
105
+ }
106
+
107
+ private function get_content($single){
108
+ return $this->catlist->get_content($single);
109
+ }
110
+
111
+ private function get_custom_fields($custom_key, $post_id){
112
+ return $this->catlist->get_custom_fields($custom_key, $post_id);
113
+ }
114
+
115
+ private function get_date($single){
116
+ return $this->catlist->get_date_to_show($single);
117
+ }
118
+
119
+ private function get_excerpt($single){
120
+ return $this->catlist->get_excerpt($single);
121
+ }
122
+
123
+ private function get_thumbnail($single){
124
+ return $this->catlist->get_thumbnail($single);
125
+ }
126
+
127
+ private function get_post_title($single){
128
+ return '<a href="' . get_permalink($single->ID).'">' . $single->post_title . '</a>';
129
+ }
130
+
131
+
132
+
133
+ }
list_cat_posts_widget.php → include/ListCategoryPostsWidget.php RENAMED
@@ -16,11 +16,12 @@ along with this program; if not, write to the Free Software
16
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
  */
18
  //Sidebar Widget file
 
19
 
20
  class ListCategoryPostsWidget extends WP_Widget{
21
 
22
  function ListCategoryPostsWidget() {
23
- parent::WP_Widget(false, $name = 'ListCategoryPostsWidget');
24
  }
25
 
26
  function widget($args, $instance) {
@@ -58,7 +59,8 @@ class ListCategoryPostsWidget extends WP_Widget{
58
  //'content' => 'no',
59
  'catlink' => $showcatlink
60
  );
61
- echo list_category_posts($atts);
 
62
  echo $lcp_result;
63
  echo $after_widget;
64
  }
16
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
  */
18
  //Sidebar Widget file
19
+ require_once 'CatListDisplayer.php';
20
 
21
  class ListCategoryPostsWidget extends WP_Widget{
22
 
23
  function ListCategoryPostsWidget() {
24
+ parent::WP_Widget(false, $name = 'List Category Posts');
25
  }
26
 
27
  function widget($args, $instance) {
59
  //'content' => 'no',
60
  'catlink' => $showcatlink
61
  );
62
+ $catlist_displayer = new CatListDisplayer($atts);
63
+ echo $catlist_displayer->display();
64
  echo $lcp_result;
65
  echo $after_widget;
66
  }
lcp_widget_form.php → include/lcp_widget_form.php RENAMED
File without changes
list_cat_posts.php CHANGED
@@ -3,7 +3,7 @@
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.16.1
7
  Author: Fernando Briano
8
  Author URI: http://picandocodigo.net/
9
  */
@@ -25,249 +25,49 @@ 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
 
29
- include('list_cat_posts_widget.php');
30
-
31
- /**
32
- *
33
- * Main plugin function: Gets the shortcode parameters, set defaults, and call the plugin's function.
34
- * @param $atts
35
- * @param $content
36
- */
37
- function catlist_func($atts, $content = null) {
38
- $atts = shortcode_atts(array(
39
- 'id' => '0',
40
- 'name' => 'default',
41
- 'orderby' => 'date',
42
- 'order' => 'desc',
43
- 'numberposts' => '5',
44
- 'date' => 'no',
45
- 'author' => 'no',
46
- 'dateformat' => get_option('date_format'),
47
- 'template' => 'default',
48
- 'excerpt' => 'no',
49
- 'exclude' => '0',
50
- 'excludeposts' => '0',
51
- 'offset' => '0',
52
- 'tags' => '',
53
- 'content' => 'no',
54
- 'catlink' => 'no',
55
- 'comments' => 'no',
56
- 'thumbnail' => 'no',
57
- 'post_type' => '',
58
- 'post_parent' => '0',
59
- 'class' => 'lcp_catlist',
60
- 'customfield_name' => '',
61
- 'customfield_value' =>'',
62
- 'customfield_display' =>''
63
- ), $atts);
64
- return list_category_posts($atts);
65
- }
66
-
67
- /* Add the shortcode to WordPress */
68
- add_shortcode('catlist', 'catlist_func');
69
-
70
- /**
71
- * Main function, this is where the flow goes and calls auxiliary functions
72
- * @param array $atts
73
- */
74
- function list_category_posts($atts){
75
- $lcp_category_id = $atts['id'];
76
- $lcp_category_name = $atts['name'];
77
-
78
- //Get the category posts:
79
- $catposts = lcp_category($lcp_category_id, $lcp_category_name, $atts);
80
-
81
- $lcp_output = '';
82
-
83
- //Link to the category:
84
- if ($atts['catlink'] == 'yes'){
85
- $cat_link = get_category_link($lcp_category_id);
86
- $cat_title = get_cat_name($lcp_category_id);
87
- $lcp_output .= '<a href="' . $cat_link . '" title="' . $cat_title . '">' . $cat_title . '</a>';
88
- }
89
-
90
- //Template code:
91
- $tplFileName = null;
92
- $possibleTemplates = array(
93
- // File locations lower in list override others
94
- TEMPLATEPATH.'/list-category-posts/'.$atts['template'].'.php',
95
- );
96
- foreach ($possibleTemplates as $key => $file) {
97
- if (is_readable($file)) {
98
- $tplFileName = $file;
99
- }
100
- }
101
- if ((!empty($tplFileName)) && (is_readable($tplFileName))) {
102
- require($tplFileName);
103
- }else{
104
- // Default template
105
- $lcp_output .= '<ul class="'.$atts['class'].'">';
106
-
107
- foreach ($catposts as $single):
108
- $lcp_output .= lcp_display_post($single, $atts);
109
- endforeach;
110
-
111
- $lcp_output .= "</ul>";
112
- }
113
- return $lcp_output;
114
- }
115
-
116
- /**
117
- * Get the categories & posts
118
- * @param string $lcp_category_id
119
- * @param string $lcp_category_name
120
- */
121
- function lcp_category($lcp_category_id, $lcp_category_name, $atts){
122
- if($lcp_category_name != 'default' && $lcp_category_id == '0'){
123
- $lcp_category = 'category_name=' . $atts['name'];
124
- }else{
125
- $lcp_category = 'cat=' . $lcp_category_id;
126
- }
127
-
128
- //Build the query for get_posts()
129
- $lcp_query = $lcp_category.'&numberposts=' . $atts['numberposts'] .
130
- '&orderby=' . $atts['orderby'] .
131
- '&order=' . $atts['order'] .
132
- '&exclude=' . $atts['excludeposts'] .
133
- '&tag=' . $atts['tags'] .
134
- '&offset=' . $atts['offset'];
135
-
136
- // Post type and post parent:
137
- if($atts['post_type']): $lcp_query .= '&post_type=' . $atts['post_type']; endif;
138
- if($atts['post_parent']): $lcp_query .= '&post_parent=' . $atts['post_parent']; endif;
139
-
140
- // Custom fields 'customfield_name' & 'customfield_value' should both be defined
141
- if($atts['customfield_name']!='' && $atts['customfield_value'] != ''):
142
- $lcp_query .= '&meta_key=' . $atts['customfield_name'] . '&meta_value=' . $atts['customfield_value'];
143
- endif;
144
-
145
- return get_posts($lcp_query);
146
- }
147
-
148
- function lcp_display_post($single, $atts){
149
- $lcp_display_output = '<li><a href="' . get_permalink($single->ID).'">' . $single->post_title . '</a>';
150
- if ($atts['comments'] == yes){
151
- $lcp_display_output .= ' (';
152
- $lcp_display_output .= lcp_comments($single);
153
- $lcp_display_output .= ')';
154
- }
155
-
156
- if ($atts['date']=='yes'){
157
- $lcp_display_output .= lcp_showdate($single, $atts['dateformat']);
158
- }
159
-
160
- if ($atts['author']=='yes'){
161
- $lcp_display_output .= " - ".lcp_showauthor($single) . '<br/>';
162
- }
163
-
164
- if($atts['customfield_display'] != ''){
165
- $lcp_display_output .= lcp_display_customfields($atts['customfield_display'], $single->ID);
166
- }
167
-
168
- if ($atts['thumbnail']=='yes'){
169
- $lcp_display_output .= lcp_thumbnail($single);
170
- }
171
-
172
- if ($atts['content']=='yes' && $single->post_content){
173
- $lcp_display_output.= lcp_content($single);
174
- }
175
-
176
- if ($atts['excerpt']=='yes' && !($atts['content']=='yes' && $single->post_content) ){
177
- $lcp_display_output .= lcp_excerpt($single);
178
- }
179
-
180
- $lcp_display_output.="</li>";
181
- return $lcp_display_output;
182
- }
183
-
184
- function lcp_comments($single){
185
- return $single->comment_count;
186
- }
187
-
188
- function lcp_showauthor($single){
189
- $lcp_userdata = get_userdata($single->post_author);
190
- return $lcp_userdata->display_name;
191
  }
192
 
193
- function lcp_showdate($single, $dateformat){
194
- return ' - ' . get_the_time($dateformat, $single);//by Verex, great idea!
195
- }
196
-
197
- function lcp_content($single){
198
- $lcp_content = $single->post_content;
199
- //Need to put some more thought on this!
200
- //Added to stop a post with catlist to display an infinite loop of catlist shortcode parsing
201
- /*if (preg_match("/\[catlist.*\]/", $lcp_content, $regmatch)){
202
- foreach ($regmatch as $match){
203
- $lcp_content = str_replace($match, '(...)',$lcp_content);
204
- }
205
- }*/
206
- $lcp_content = apply_filters('the_content', $lcp_content); // added to parse shortcodes
207
- $lcp_content = str_replace(']]>', ']]&gt', $lcp_content); // added to parse shortcodes
208
- return '<p>' . $lcp_content . '</p>';
209
- }
210
-
211
-
212
- function lcp_excerpt($single){
213
- if($single->post_excerpt){
214
- return '<p>' . $single->post_excerpt . '</p>';
215
- }
216
- $lcp_excerpt = strip_tags($single->post_content);
217
- if ( post_password_required($post) ) {
218
- $lcp_excerpt = __('There is no excerpt because this is a protected post.');
219
- return $lcp_excerpt;
220
- }
221
- if (strlen($lcp_excerpt) > 255) {
222
- $lcp_excerpt = substr($lcp_excerpt, 0, 252) . '...';
223
- }
224
- return '<p>' . $lcp_excerpt . '</p>';
225
- }
226
-
227
- /**
228
- * Get the post Thumbnail
229
- * @see http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
230
- * @param unknown_type $single
231
- */
232
- function lcp_thumbnail($single){
233
- $lcp_thumbnail = '';
234
- if ( has_post_thumbnail($single->ID) ) {
235
- $lcp_thumbnail = get_the_post_thumbnail($single->ID);
236
- }
237
- return $lcp_thumbnail;
238
- }
239
-
240
- /**
241
- * Display custom fields.
242
- * @see http://codex.wordpress.org/Function_Reference/get_post_custom
243
- * @param string $custom_key
244
- * @param int $post_id
245
- */
246
- function lcp_display_customfields($custom_key, $post_id){
247
- $lcp_customs = '';
248
- //Doesn't work for many when having spaces:
249
- $custom_key = trim($custom_key);
250
- //Create array for many fields:
251
- $custom_array = explode(",", $custom_key);
252
- //Get post custom fields:
253
- $custom_fields = get_post_custom($post_id);
254
- //Loop on custom fields and if there's a value, add it:
255
- foreach ($custom_array as $something){
256
- $my_custom_field = $custom_fields[$something];
257
- if (sizeof($my_custom_field) > 0 ):
258
- foreach ( $my_custom_field as $key => $value ){
259
- $lcp_customs .= "<div class=\"lcp-customfield\">" . $something. " : " . $value . "</div>";
260
- }
261
- endif;
262
- }
263
- return $lcp_customs;
264
- }
265
-
266
- /** TODO - These are the todo's for a 1.0 release:
267
- * -Pagination
268
- * -Simplify template system
269
- * -i18n
270
- */
271
-
272
-
273
- ?>
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.17
7
  Author: Fernando Briano
8
  Author URI: http://picandocodigo.net/
9
  */
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
+ 'author' => 'no',
46
+ 'dateformat' => get_option('date_format'),
47
+ 'template' => 'default',
48
+ 'excerpt' => 'no',
49
+ 'exclude' => '0',
50
+ 'excludeposts' => '0',
51
+ 'offset' => '0',
52
+ 'tags' => '',
53
+ 'content' => 'no',
54
+ 'catlink' => 'no',
55
+ 'comments' => 'no',
56
+ 'thumbnail' => 'no',
57
+ 'post_type' => '',
58
+ 'post_parent' => '0',
59
+ 'class' => 'lcp_catlist',
60
+ 'customfield_name' => '',
61
+ 'customfield_value' =>'',
62
+ 'customfield_display' =>''
63
+ ), $atts);
64
+
65
+
66
+ $catlist_displayer = new CatListDisplayer($atts);
67
+ return $catlist_displayer->display();
68
+
69
+ }
70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  }
72
 
73
+ add_shortcode( 'catlist', array('ListCategoryPosts', 'catlist_func') );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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: 2.8
6
  Tested up to: 3.1
7
- Stable tag: 0.16.1
8
 
9
  == Description ==
10
  List Category Posts is a simple WordPress plugin which 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.
@@ -17,6 +17,8 @@ Compatible with WordPress 3.0 and default Twenty Ten theme (http://wordpress.org
17
 
18
  Usage: [catlist argument1=value1 argument2=value2].
19
 
 
 
20
  Tell us how you use this plugin!
21
  http://foro.picandocodigo.net/discussion/261/do-you-like-list-category-posts-read-me
22
 
@@ -68,7 +70,7 @@ If you use both arguments (wrong!), List Category Posts will show the posts from
68
 
69
  * **dateformat** - Format of the date output. Default is get_option('date_format'). Check http://codex.wordpress.org/Formatting_Date_and_Time for possible formats.
70
 
71
- * **template** - File name of template from templates directory without extension. Example: For 'template.php' value is only 'template'. Default is 'default' that means template in code of plugin not in template file, that's an unordered list (ul html tag) with a CSS class. This class can be passed as a parameter or by default it's: 'lcp_catlist'
72
 
73
  * **excerpt** - Display the post's excerpt. Default is 'no', use excerpt=yes to activate it.
74
 
@@ -78,7 +80,7 @@ If you use both arguments (wrong!), List Category Posts will show the posts from
78
 
79
  * **content** - Show the full content of the post. Default is 'no'. Ex: [catlist content=yes]
80
 
81
- * **catlink** - Show the title of the category with a link to the category. Use the template system to customize its display using the variable $cat_link_string. Default is 'no'. Ex: [catlist catlink=yes].
82
 
83
  * **comments** - Show comments count for each post. Default is 'no'. Ex: [catlist comments=yes].
84
 
@@ -107,6 +109,9 @@ Your comments and feedback are welcome at: http://foro.picandocodigo.net/categor
107
 
108
  == Upgrade Notice ==
109
 
 
 
 
110
  = 0.13.2 =
111
  Thumbnail parameter 'thumbnails' changed to 'thumbnail.
112
 
@@ -117,10 +122,14 @@ Template system has changed. Now the posts loop must be defined inside the templ
117
  Widget built for WordPress 2.8's Widget API, so you need at least WP 2.8 to use the widget.
118
 
119
  = 0.9 =
120
- Template system has changed. Custom templates should be stored in wordpress theme folder.
121
 
122
  == Changelog ==
123
 
 
 
 
 
124
  = 0.16.1 =
125
  * Fixed shortcode nesting.
126
 
4
  Tags: list, categories, posts, cms
5
  Requires at least: 2.8
6
  Tested up to: 3.1
7
+ Stable tag: 0.17
8
 
9
  == Description ==
10
  List Category Posts is a simple WordPress plugin which 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.
17
 
18
  Usage: [catlist argument1=value1 argument2=value2].
19
 
20
+ *Notice*: On version 0.17 the plugin was again rewritten as objects. This added a few features, please read the documentation on it.
21
+
22
  Tell us how you use this plugin!
23
  http://foro.picandocodigo.net/discussion/261/do-you-like-list-category-posts-read-me
24
 
70
 
71
  * **dateformat** - Format of the date output. Default is get_option('date_format'). Check http://codex.wordpress.org/Formatting_Date_and_Time for possible formats.
72
 
73
+ * **template** - File name of template from templates directory without extension. Example: For 'template.php' value is only 'template'. Default is 'default', which displays an unordered list (ul html tag) with a CSS class. This class can be passed as a parameter or by default it's: 'lcp_catlist'. You can also use the default 'div' value. This will output a div with the 'lcp_catlist' CSS class (or one you pass as parameter with the class argument). The inner items (posts) will be displayed between p tags.
74
 
75
  * **excerpt** - Display the post's excerpt. Default is 'no', use excerpt=yes to activate it.
76
 
80
 
81
  * **content** - Show the full content of the post. Default is 'no'. Ex: [catlist content=yes]
82
 
83
+ * **catlink** - Show the title of the category with a link to the category. Use the template system to customize its display using the variable $cat_link_string. 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.
84
 
85
  * **comments** - Show comments count for each post. Default is 'no'. Ex: [catlist comments=yes].
86
 
109
 
110
  == Upgrade Notice ==
111
 
112
+ = 0.17 =
113
+ Upgrade your templates: Templates system was rewritten, so your current templates will probably not work. Check out the new default.php file on /templates to see the simpler new way to work with templates.
114
+
115
  = 0.13.2 =
116
  Thumbnail parameter 'thumbnails' changed to 'thumbnail.
117
 
122
  Widget built for WordPress 2.8's Widget API, so you need at least WP 2.8 to use the widget.
123
 
124
  = 0.9 =
125
+ Template system has changed. Custom templates should be stored in WordPress theme folder.
126
 
127
  == Changelog ==
128
 
129
+ = 0.17 =
130
+ * Major rewrite. The whole code was rewritten using objects. It's easier now to develop for List Category Posts.
131
+ * Both STYLESHEETPATH and TEMPLATEPATH are checked for templates.
132
+
133
  = 0.16.1 =
134
  * Fixed shortcode nesting.
135
 
templates/README DELETED
@@ -1,11 +0,0 @@
1
- Templates for the List Category Plugin are searched for in your WordPress theme's folder.
2
- You should create a folder named "list-category-posts" under [i]wp-content/themes/your-theme-folder[/i].
3
-
4
- Template files are .php files. You can use the included template as an example to start.
5
- You can find it in the plugin's template folder under the name default.php. To use a template, use this code:
6
- [catlist id=1 template=default]
7
- If the template file is default.php.
8
- You can have as many different templates as you want, and use them in different pages and posts.
9
-
10
- More info / help:
11
- http://foro.picandocodigo.net/viewtopic.php?f=28&t=253
 
 
 
 
 
 
 
 
 
 
 
templates/default.php CHANGED
@@ -25,42 +25,58 @@ 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
- //Show category?
29
- $lcp_output = ($cat_link_string != '') ? '<p><strong>' . $cat_link_string . '</strong></p>' : '';
30
-
31
- $lcp_output .= '<ul class="lcp_catlist">';//For default ul
32
- //Posts loop:
33
- foreach($catposts as $single):
34
- $lcp_output .= '<li><a href="' . get_permalink($single->ID) . '">' . $single->post_title . '</a>';
35
- //Show comments?
36
- if($atts['comments'] == yes){
37
- $lcp_output .= ' (' . $single->comment_count . ')';
38
- }
39
- //Style for date:
40
- if($atts['date']=='yes'){
41
- $lcp_output .= ' - ' . get_the_time($atts['dateformat'], $single);
42
- }
43
- //Show author?
44
- if($atts['author']=='yes'){
45
- $lcp_userdata = get_userdata($single->post_author);
46
- $lcp_output .=" - ".$lcp_userdata->display_name;
47
- }
48
- //Show thumbnail?
49
- if($atts['thumbnail']=='yes'){
50
- $lcp_output .= '<div class="lcp_thumbnail">'. lcp_thumbnails($single) . '</div>';
51
- }
52
-
53
- //Show content?
54
- if($atts['content']=='yes' && $single->post_content){
55
- $lcpcontent = apply_filters('the_content', $single->post_content); // added to parse shortcodes
56
- $lcpcontent = str_replace(']]>', ']]&gt', $lcpcontent); // added to parse shortcodes
57
- $lcp_output .= '<p>' . $lcpcontent . '</p>'; // line tweaked to output filtered content
58
- }
59
- //Show excerpt?
60
- if($atts['excerpt']=='yes' && !($atts['content']=='yes' && $single->post_content) ){
61
- $lcp_output .= lcp_excerpt($single);
62
- }
63
- $lcp_output .='</li>';
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  endforeach;
65
- $lcp_output .= '</ul>';
 
 
 
66
  ?>
25
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
  */
27
 
28
+ /**
29
+ * The format for templates changed since version 0.17.
30
+ * Since this code is included inside CatListDisplayer, $this refers to
31
+ * the instance of CatListDisplayer that called this file.
32
+ */
33
+
34
+ /* This is the string which will gather all the information.
35
+ * We're starting it */
36
+ $lcp_display_output = '';
37
+
38
+ //Add 'starting' tag. Here, I'm using an unordered list (ul) as an example:
39
+ $lcp_output .= '<ul class="lcp_catlist">';
40
+
41
+ /**
42
+ * Posts loop.
43
+ * The code here will be executed for every post in the category.
44
+ * As you can see, the different options are being called from functions on the
45
+ * $this variable which is a CatListDisplayer. The CatListDisplayer
46
+ */
47
+ foreach ($this->catlist->get_categories_posts() as $single):
48
+ //Start a List Item for each post:
49
+ $lcp_display_output .= "<li>";
50
+
51
+ //Show the title and link to the post:
52
+ $lcp_display_output .= $this->get_post_title($single);
53
+
54
+ //Show comments:
55
+ $lcp_display_output .= $this->get_comments($single);
56
+
57
+ //Show date:
58
+ $lcp_display_output .= ' ' . $this->get_date($single);
59
+
60
+ //Show author
61
+ $lcp_display_output .= '<br/>' . __('Author') . ': ' . $this->get_author($single) . '<br/>';
62
+
63
+ //Custom fields:
64
+ $lcp_display_output .= $this->get_custom_fields($this->params['customfield_display'], $single->ID);
65
+
66
+ //Post Thumbnail
67
+ $lcp_display_output .= $this->get_thumbnail($single);
68
+
69
+ //Post content
70
+ $lcp_display_output .= $this->get_content($single);
71
+
72
+ //Post excerpt
73
+ $lcp_display_output .= $this->get_excerpt($single);
74
+
75
+ //Close li tag
76
+ $lcp_display_output .= '</li>';
77
  endforeach;
78
+
79
+ $lcp_display_output .= '</ul>';
80
+ $this->lcp_output = $lcp_display_output;
81
+
82
  ?>
templates/readme.txt ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Templates for the List Category Plugin are searched for in your WordPress theme's folder. You should create a folder named "list-category-posts" under 'wp-content/themes/your-theme-folder'.
2
+
3
+ Template files are .php files.
4
+
5
+ You can use the included template as an example to start. You can find it in the plugin's template folder under the name default.php. To use a template, use this code:
6
+ [catlist id=1 template=templatename]
7
+ If the template file were templatename.php.
8
+
9
+ You can have as many different templates as you want, and use them in different pages and posts. The template code is pretty well documented, so if you're a bit familiar with HTML and PHP, you'll have no problems creating your own template. I'm planning on reworking the template system in order to have a really user friendly way to create templates, but in the meantime, I'm slowly improving the existing system.
10
+
11
+ More info / help:
12
+ http://picandocodigo.net/programacion/wordpress/list-category-posts-wordpress-plugin-english/