List category posts - Version 0.11

Version Description

  • Automatic excerpt added in case the user didn't specifically write an excerpt.
  • Widget has been finally fixed. The attributes finally save themselves, and the widget works as expected :D
Download this release

Release Info

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

Code changes from version 0.10.1 to 0.11

lcp_widget_form.php CHANGED
@@ -16,32 +16,34 @@ 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
 
19
- $instance = wp_parse_args( (array) $instance, array( 'title' => '',
20
- 'categoryid' => '',
21
- 'limit' => '',
22
- 'orderby'=>'',
23
- 'order'=>'',
24
- 'date'=>'',
25
- 'author'=>'',
26
- 'excerpt'=>'',
27
- 'exclude'=>'',
28
- 'excludeposts'=>'',
29
- 'offset'=>'',
30
- 'catlink'=>'' ) );
31
- $title = strip_tags($instance['title']);
32
- $limit = strip_tags($instance['limit']);
33
- $orderby = strip_tags($instance['orderby']);
34
- $order = strip_tags($instance['order']);
35
- $date = strip_tags($instance['date']);
36
- $author = strip_tags($instance['author']);
37
- $exclude = strip_tags($instance['exclude']);
38
- $excludeposts = strip_tags($instance['excludeposts']);
39
- $offset = strip_tags($instance['offset']);
40
- $catlink = strip_tags($instance['catlink']);
41
- $categoryid = strip_tags($instance['categoryid']);
42
-
 
 
43
  ?>
44
- <?php //var_dump($instance);?>
45
  <p><label for="<?php echo $this->get_field_id('title'); ?>">Title: <br/>
46
  <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>"
47
  name="<?php echo $this->get_field_name('title'); ?>" type="text"
@@ -107,20 +109,21 @@ $instance = wp_parse_args( (array) $instance, array( 'title' => '',
107
 
108
  <p>
109
  <label>Show: </label><br/>
110
- <input type="radio"
111
- <?php if ($date == 'on' ) : echo ' checked = "checked" '; endif; ?>
112
- name="<?php echo $this->get_field_name('date'); ?>"
113
- value="<?php echo attribute_escape($date); ?>">Date<br>
114
- <input type="radio"
115
- <?php if ($author == 'on' ) : echo ' checked = "checked" '; endif; ?>
116
- name="<?php echo $this->get_field_name('author'); ?>"
117
- value="<?php echo attribute_escape($author); ?>">Author<br>
118
- <input type="radio"
119
- <?php if ($catlink == 'on' ) : echo ' checked = "checked" '; endif; ?>
120
- name="<?php echo $this->get_field_name('catlink'); ?>"
121
- value="<?php echo attribute_escape($catlink); ?>">Link to category<br>
122
- <input type="radio"
123
- <?php if ($excerpt == 'on' ) : echo ' checked = "checked" '; endif; ?>
124
- name="<?php echo $this->get_field_name('excerpt'); ?>"
125
- value="<?php echo attribute_escape($excerpt); ?>">Excerpt<br>
 
126
  </p>
16
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
  */
18
 
19
+ $instance = wp_parse_args( (array) $instance, array(
20
+ 'title' => '',
21
+ 'categoryid' => '',
22
+ 'limit' => '',
23
+ 'orderby'=>'',
24
+ 'order'=>'',
25
+ 'show_date'=>'',
26
+ 'show_author'=>'',
27
+ 'show_excerpt'=>'',
28
+ 'exclude'=>'',
29
+ 'excludeposts'=>'',
30
+ 'offset'=>'',
31
+ 'show_catlink'=>'' ) );
32
+ $title = strip_tags($instance['title']);
33
+ $limit = strip_tags($instance['limit']);
34
+ $orderby = strip_tags($instance['orderby']);
35
+ $order = strip_tags($instance['order']);
36
+ $showdate = strip_tags($instance['showdate']);
37
+ $showauthor = strip_tags($instance['author']);
38
+ $exclude = strip_tags($instance['exclude']);
39
+ $excludeposts = strip_tags($instance['excludeposts']);
40
+ $offset = strip_tags($instance['offset']);
41
+ $showcatlink = strip_tags($instance['catlink']);
42
+ $categoryid = strip_tags($instance['categoryid']);
43
+ $showexcerpt = strip_tags($instance['excerpt']);
44
+ //var_dump($instance);
45
  ?>
46
+
47
  <p><label for="<?php echo $this->get_field_id('title'); ?>">Title: <br/>
48
  <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>"
49
  name="<?php echo $this->get_field_name('title'); ?>" type="text"
109
 
110
  <p>
111
  <label>Show: </label><br/>
112
+ <p>
113
+ <input type="checkbox"
114
+ <?php checked( (bool) $instance['show_date'], true ); ?>
115
+ name="<?php echo $this->get_field_name( 'show_date' ); ?>" />Date
116
+ </p><p>
117
+ <input type="checkbox"
118
+ <?php checked( (bool) $instance['show_author'], true ); ?>
119
+ name="<?php echo $this->get_field_name( 'show_author' ); ?>" />Author
120
+ </p><p>
121
+ <input type="checkbox"
122
+ <?php checked( (bool) $instance['show_catlink'], true ); ?>
123
+ name="<?php echo $this->get_field_name( 'show_catlink' ); ?>" />Link to category
124
+ </p><p>
125
+ <input type="checkbox"
126
+ <?php checked( (bool) $instance['show_excerpt'], true ); ?>
127
+ name="<?php echo $this->get_field_name( 'show_excerpt' ); ?>" />Excerpt
128
+ </p>
129
  </p>
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.10.1
7
  Author: Fernando Briano
8
  Author URI: http://picandocodigo.net/
9
  */
@@ -46,10 +46,12 @@ function catlist_func($atts, $content=null) {
46
  'offset' => '0',
47
  'tags' => '',
48
  'content' => 'no',
49
- 'catlink' => 'no'
 
50
  ), $atts);
51
  return list_category_posts($atts);
52
  }
 
53
  add_shortcode('catlist', 'catlist_func');
54
 
55
  function list_category_posts($atts){
@@ -80,7 +82,6 @@ function list_category_posts($atts){
80
  $tplFileName = null;
81
  $possibleTemplates = array(
82
  // File locations lower in list override others
83
- dirname(__FILE__).'/templates/'.$atts['template'].'.php',
84
  STYLESHEETPATH.'/list-category-posts/'.$atts['template'].'.php',
85
  );
86
  foreach($possibleTemplates as $key => $file) {
@@ -92,41 +93,57 @@ function list_category_posts($atts){
92
  require($tplFileName);
93
  }else{
94
  if ($cat_link_string != ''){
95
- $output = '<p><strong>' . $cat_link_string . '</strong></p>';
96
  }else{
97
- $output = '';
98
  }
99
- $output .= '<ul class="lcp_catlist">';//For default ul
100
  foreach($catposts as $single):
101
- $output .= '<li><a href="' . get_permalink($single->ID).'">' . $single->post_title . '</a>';
102
  if($atts['date']=='yes'){
103
- $output .= ' - ' . get_the_time($atts['dateformat'], $single);//by Verex, great idea!
104
  }
105
  if($atts['author']=='yes'){
106
  $lcp_userdata = get_userdata($single->post_author);
107
- $output.=" - ".$lcp_userdata->display_name . '<br/>';
108
  }
109
  if($atts['content']=='yes' && $single->post_content){
110
- $lcpcontent = apply_filters('the_content', $single->post_content); // added to parse shortcodes
111
- $lcpcontent = str_replace(']]>', ']]&gt', $lcpcontent); // added to parse shortcodes
112
- $output.= '<p>' . $lcpcontent . '</p>'; // line tweaked to output filtered content
113
  }
114
- if($atts['excerpt']=='yes' && $single->post_excerpt && !($atts['content']=='yes' && $single->post_content) ){
115
- $output .= "<p>$single->post_excerpt</p>";
116
  }
117
- $output.="</li>";
118
  endforeach;
119
- $output .= "</ul>";
120
  }
121
- return $output;
 
 
 
 
 
 
122
  }
123
 
124
- function lcp_add_option_page(){
125
- add_options_page('List Category Posts', 'List Category Posts', 'manage_options','list-category-posts/list_cat_posts_options.php');
 
 
 
 
 
 
 
 
 
 
 
126
  }
127
 
128
  /** TODO
129
- * -Add auto excerpt
130
  * -Images (preview or thumbnail, whatever, I have to dig into this
 
 
131
  */
132
  ?>
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.11
7
  Author: Fernando Briano
8
  Author URI: http://picandocodigo.net/
9
  */
46
  'offset' => '0',
47
  'tags' => '',
48
  'content' => 'no',
49
+ 'catlink' => 'no',
50
+ 'comments' => 'no'
51
  ), $atts);
52
  return list_category_posts($atts);
53
  }
54
+
55
  add_shortcode('catlist', 'catlist_func');
56
 
57
  function list_category_posts($atts){
82
  $tplFileName = null;
83
  $possibleTemplates = array(
84
  // File locations lower in list override others
 
85
  STYLESHEETPATH.'/list-category-posts/'.$atts['template'].'.php',
86
  );
87
  foreach($possibleTemplates as $key => $file) {
93
  require($tplFileName);
94
  }else{
95
  if ($cat_link_string != ''){
96
+ $lcp_output = '<p><strong>' . $cat_link_string . '</strong></p>';
97
  }else{
98
+ $lcp_output = '';
99
  }
100
+ $lcp_output .= '<ul class="lcp_catlist">';//For default ul
101
  foreach($catposts as $single):
102
+ $lcp_output .= '<li><a href="' . get_permalink($single->ID).'">' . $single->post_title . '</a>';
103
  if($atts['date']=='yes'){
104
+ $lcp_output .= ' - ' . get_the_time($atts['dateformat'], $single);//by Verex, great idea!
105
  }
106
  if($atts['author']=='yes'){
107
  $lcp_userdata = get_userdata($single->post_author);
108
+ $lcp_output.=" - ".$lcp_userdata->display_name . '<br/>';
109
  }
110
  if($atts['content']=='yes' && $single->post_content){
111
+ $lcp_output.= lcp_content($single); // line tweaked to output filtered content
 
 
112
  }
113
+ if($atts['excerpt']!='yes' && !($atts['content']=='yes' && $single->post_content) ){
114
+ $lcp_output .= lcp_excerpt($single);
115
  }
116
+ $lcp_output.="</li>";
117
  endforeach;
118
+ $lcp_output .= "</ul>";
119
  }
120
+ return $lcp_output;
121
+ }
122
+
123
+ function lcp_content($single){
124
+ $lcp_content = apply_filters('the_content', $single->post_content); // added to parse shortcodes
125
+ $lcp_content = str_replace(']]>', ']]&gt', $lcp_content); // added to parse shortcodes
126
+ return '<p>' . $lcp_content . '</p>';
127
  }
128
 
129
+ function lcp_excerpt($single){
130
+ if($single->post_excerpt){
131
+ return $single->post_excerpt;
132
+ }
133
+ $lcp_excerpt = strip_tags($single->post_content);
134
+ if ( post_password_required($post) ) {
135
+ $lcp_excerpt = __('There is no excerpt because this is a protected post.');
136
+ return $lcp_excerpt;
137
+ }
138
+ if (strlen($lcp_excerpt) > 255) {
139
+ $lcp_excerpt = substr($lcp_excerpt, 0, 252) . '...';
140
+ }
141
+ return '<p>' . $lcp_excerpt . '</p>';
142
  }
143
 
144
  /** TODO
 
145
  * -Images (preview or thumbnail, whatever, I have to dig into this
146
+ * -Pagination
147
+ * -i18n
148
  */
149
  ?>
list_cat_posts_widget.php CHANGED
@@ -34,47 +34,32 @@ class ListCategoryPostsWidget extends WP_Widget{
34
  $offset = (is_numeric($instance['offset'])) ? $instance['offset'] : 0;
35
  $category_id = $instance['categoryid'];
36
  $dateformat = ($instance['dateformat']) ? $instance['dateformat'] : get_option('date_format');
37
-
38
- echo $before_widget;
39
-
40
- //Link to the category:
41
- $cat_link_string = '';
42
- if ($instance['catlink'] == 'on'){
43
- $cat_link = get_category_link($category_id);
44
- $cat_data = get_category($category_id);
45
- $cat_title = $cat_data->name;
46
- $cat_link_string = '<a href=' . $cat_link . ' title="' . $cat_title . '">' . $cat_title . '</a>';
47
- }
48
- $lcp_result = $cat_link_string;
49
-
50
- //Build the query for get_posts()
51
- $lcp_catposts = get_posts('category=' . $category_id .
52
- '&numberposts=' . $limit .
53
- '&orderby=' . $atts['orderby'] .
54
- '&order=' . $atts['order'] .
55
- '&exclude=' . $atts['excludeposts'] .
56
- '&offset=' . $atts['offset'] );
57
-
58
- $lcp_result .= '<ul class="lcp_catlist">';
59
-
60
- foreach($lcp_catposts as $lcp_single):
61
- $lcp_result .= '<li><a href="' . get_permalink($lcp_single->ID).'">' . $lcp_single->post_title . '</a>';
62
- if($instance['date'] == 'on') :
63
- $lcp_result .= ' - ' . get_the_time($atts['dateformat'], $lcp_single);//by Verex, great idea!
64
- endif;
65
- if($instance['author'] =='on') :
66
- $lcp_userdata = get_userdata($lcp_single->post_author);
67
- $lcp_result .= " - ".$lcp_userdata->user_nicename . '<br/>';
68
- endif;
69
- if($instance['excerpt'] == 'on' && $lcp_single->post_excerpt && !($instance['content'] == 'no' && $lcp_single->post_content) ) :
70
- $lcp_result .= "<p>$lcp_single->post_excerpt</p>";
71
- endif;
72
- $lcp_result .= "</li>";
73
- endforeach;
74
-
75
- $lcp_result .= "</ul>";
76
- echo '<h2>' . $title . '</h2>';
77
- echo $lcp_result;
78
  echo $after_widget;
79
  }
80
 
34
  $offset = (is_numeric($instance['offset'])) ? $instance['offset'] : 0;
35
  $category_id = $instance['categoryid'];
36
  $dateformat = ($instance['dateformat']) ? $instance['dateformat'] : get_option('date_format');
37
+ $showdate = ($instance['show_date'] == 'on') ? 'yes' : 'no';
38
+ $showexcerpt = ($instance['show_excerpt'] == 'on') ? 'yes' : 'no';
39
+ $showauthor = ($instance['show_author'] == 'on') ? 'yes' : 'no';
40
+ $showcatlink = ($instance['show_catlink'] == 'on') ? 'yes' : 'no';
41
+
42
+ echo $before_widget;
43
+ echo $before_title . $title . $after_title;
44
+ $atts = array(
45
+ 'id' => $category_id,
46
+ 'orderby' => $orderby,
47
+ 'order' => $order,
48
+ 'numberposts' => $limit,
49
+ 'date' => $showdate,
50
+ 'author' => $showauthor,
51
+ 'dateformat' => $dateformat,
52
+ 'template' => 'default',
53
+ 'excerpt' => $showexcerpt,
54
+ 'exclude' => $exclude,
55
+ 'excludeposts' => $excludeposts,
56
+ 'offset' => $offset,
57
+ //'tags' => '',
58
+ //'content' => 'no',
59
+ 'catlink' => $showcatlink
60
+ );
61
+ echo list_category_posts($atts);
62
+ echo $lcp_result;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  echo $after_widget;
64
  }
65
 
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: fernandobt
3
  Donate Link: http://picandocodigo.net/programacion/wordpress/list-category-posts-wordpress-plugin-english/
4
  Tags: list, categories, posts, cms
5
  Requires at least: 2.8
6
- Tested up to: 2.9.2
7
- Stable tag: 0.10.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. Great to use WordPress as a CMS, and create pages with several categories posts.
@@ -99,6 +99,11 @@ Template system has changed. Custom templates should be stored in wordpress them
99
 
100
  == Changelog ==
101
 
 
 
 
 
 
102
  = 0.10.1 =
103
  * Small fix - added ul tags to default template.
104
  * Compatible WordPress 3.0 with Twenty Ten theme (thanks again Doug Joseph :) )
3
  Donate Link: http://picandocodigo.net/programacion/wordpress/list-category-posts-wordpress-plugin-english/
4
  Tags: list, categories, posts, cms
5
  Requires at least: 2.8
6
+ Tested up to: 3.0
7
+ Stable tag: 0.11
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. Great to use WordPress as a CMS, and create pages with several categories posts.
99
 
100
  == Changelog ==
101
 
102
+ = 0.11 =
103
+ * Automatic excerpt added in case the user didn't specifically write an excerpt.
104
+ * Widget has been finally fixed. The attributes finally save themselves, and the widget works as expected :D
105
+
106
+
107
  = 0.10.1 =
108
  * Small fix - added ul tags to default template.
109
  * Compatible WordPress 3.0 with Twenty Ten theme (thanks again Doug Joseph :) )
templates/default.php CHANGED
@@ -27,34 +27,36 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27
 
28
  //Show category?
29
  if ($cat_link_string != ''){
30
- $output = '<p><strong>' . $cat_link_string . '</strong></p>';
31
  }else{
32
- $output = '';
33
  }
34
- $output .= '<ul class="lcp_catlist">';//For default ul
35
  //Posts loop:
36
  foreach($catposts as $single):
37
- $output .= '<li><a href="' . get_permalink($single->ID) . '">' . $single->post_title . '</a>';
38
  //Style for date:
39
  if($atts['date']=='yes'){
40
- $output.= ' - ' . get_the_time($atts['dateformat'], $single);
41
  }
42
  //Show author?
43
  if($atts['author']=='yes'){
44
  $lcp_userdata = get_userdata($single->post_author);
45
- $output.=" - ".$lcp_userdata->display_name;
46
  }
47
  //Show content?
48
  if($atts['content']=='yes' && $single->post_content){
49
  $lcpcontent = apply_filters('the_content', $single->post_content); // added to parse shortcodes
50
  $lcpcontent = str_replace(']]>', ']]&gt', $lcpcontent); // added to parse shortcodes
51
- $output.= '<p>' . $lcpcontent . '</p>'; // line tweaked to output filtered content
52
  }
53
  //Show excerpt?
54
- if($atts['excerpt']=='yes' && $single->post_excerpt && !($atts['content']=='yes' && $single->post_content) ){
55
- $output .= '<p>' . $single->post_excerpt . '</p>';
56
  }
57
- $output.='</li>';
58
  endforeach;
59
- $output.='</ul>';
 
 
60
  ?>
27
 
28
  //Show category?
29
  if ($cat_link_string != ''){
30
+ $lcp_output = '<p><strong>' . $cat_link_string . '</strong></p>';
31
  }else{
32
+ $lcp_output = '';
33
  }
34
+ $lcp_output .= '<ul class="lcp_catlist">';//For default ul
35
  //Posts loop:
36
  foreach($catposts as $single):
37
+ $lcp_output .= '<li><a href="' . get_permalink($single->ID) . '">' . $single->post_title . '</a>';
38
  //Style for date:
39
  if($atts['date']=='yes'){
40
+ $lcp_output .= ' - ' . get_the_time($atts['dateformat'], $single);
41
  }
42
  //Show author?
43
  if($atts['author']=='yes'){
44
  $lcp_userdata = get_userdata($single->post_author);
45
+ $lcp_output .=" - ".$lcp_userdata->display_name;
46
  }
47
  //Show content?
48
  if($atts['content']=='yes' && $single->post_content){
49
  $lcpcontent = apply_filters('the_content', $single->post_content); // added to parse shortcodes
50
  $lcpcontent = str_replace(']]>', ']]&gt', $lcpcontent); // added to parse shortcodes
51
+ $lcp_output .= '<p>' . $lcpcontent . '</p>'; // line tweaked to output filtered content
52
  }
53
  //Show excerpt?
54
+ if($atts['excerpt']=='yes' && !($atts['content']=='yes' && $single->post_content) ){
55
+ $lcp_output .= '<p>' . lcp_excerpt($single) . '</p>';
56
  }
57
+ $lcp_output .='</li>';
58
  endforeach;
59
+ $lcp_output .= '</ul>';
60
+
61
+
62
  ?>