List category posts - Version 0.5

Version Description

  • Readme.txt validation.
  • Added 'excerpt' parameter. You can now show the excerpt for each post.
  • Added 'dateformat' parameter. Format of the date output. Default is get_option('date_format') - by Verex
  • Added 'template' parameter. Now you can choose template for output of the plugin. 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 -by Verex
Download this release

Release Info

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

Code changes from version 0.4.1 to 0.5

Files changed (3) hide show
  1. list_cat_posts.php +58 -38
  2. readme.txt +28 -21
  3. templates/default.php +42 -0
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.4.1
7
  Author: Fernando Briano
8
  Author URI: http://picandocodigo.net/wordpress/
9
  */
@@ -12,7 +12,7 @@ Author URI: http://picandocodigo.net/wordpress/
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,
@@ -27,49 +27,69 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27
 
28
  //Shortcode [catlist parameter="value"]
29
  function catlist_func($atts, $content=null) {
30
- $atts=shortcode_atts(array(
31
- 'id' => '0',
32
- 'name' => 'default',
33
- 'orderby' => 'date',
34
- 'order' => 'desc',
35
- 'numberposts' => '5',
36
- 'date' => 'no',
37
- 'author' => 'no'
38
- ), $atts);
39
- return list_category_posts($atts);
 
 
 
40
  }
41
  add_shortcode('catlist', 'catlist_func');
42
 
43
  function list_category_posts($atts){
44
- $output = "<ul class='lcp_catlist'>";
45
- if($atts['name']!='default' && $atts['id']!='0'){
46
- $category='category_name='.$atts['name'];
47
- }else{
48
- $category='category='.$atts['id'];
49
- }
50
- /*I should check this for the next version: ('category__in' => array(2,6))
51
- to allow posts from many categories.
52
- http://codex.wordpress.org/Template_Tags/get_posts#Parameters:_WordPress_2.6.2B */
53
-
54
- //Build the query for get_posts()
55
- $catposts=get_posts($category.'&numberposts='.$atts['numberposts'].'&orderby='.$atts['orderby'].'&order='.$atts['order']);
56
- foreach($catposts as $single):
57
- $output .= "<li><a href='".get_permalink($single->ID)."'>".$single->post_title."</a>";
58
- if($atts['date']=='yes'){
59
- $output.=" - ".$single->post_date;
60
- }
61
- if($atts['author']=='yes'){
62
- $lcp_userdata = get_userdata($single->post_author);
63
- $output.=" - ".$lcp_userdata->user_nicename;
64
- }
65
- $output.="</li>";
66
- endforeach;
67
- $output .= "</ul>";
68
- return $output;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  }
70
 
71
  function lcp_add_option_page(){
72
- add_options_page('List Category Posts', 'List Category Posts', 'manage_options','list-category-posts/list_cat_posts_options.php');
73
  }
74
 
75
  //Sidebar Widget:
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.5
7
  Author: Fernando Briano
8
  Author URI: http://picandocodigo.net/wordpress/
9
  */
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,
27
 
28
  //Shortcode [catlist parameter="value"]
29
  function catlist_func($atts, $content=null) {
30
+ $atts=shortcode_atts(array(
31
+ 'id' => '0',
32
+ 'name' => 'default',
33
+ 'orderby' => 'date',
34
+ 'order' => 'desc',
35
+ 'numberposts' => '5',
36
+ 'date' => 'no',
37
+ 'author' => 'no',
38
+ 'dateformat' => get_option('date_format'), //By Verex
39
+ 'template' => 'default',
40
+ 'excerpt' => 'no'
41
+ ), $atts);
42
+ return list_category_posts($atts);
43
  }
44
  add_shortcode('catlist', 'catlist_func');
45
 
46
  function list_category_posts($atts){
47
+ if($atts['name']!='default' && $atts['id']!='0'){
48
+ $category = 'category_name=' . $atts['name'];
49
+ }else{
50
+ $category = 'category=' . $atts['id'];
51
+ }
52
+ /*I should check this for the next version: ('category__in' => array(2,6))
53
+ to allow posts from many categories.
54
+ http://codex.wordpress.org/Template_Tags/get_posts#Parameters:_WordPress_2.6.2B */
55
+ //Build the query for get_posts()
56
+ $catposts = get_posts($category.'&numberposts=' .
57
+ $atts['numberposts'] . '&orderby=' . $atts['orderby'] .
58
+ '&order=' . $atts['order']);
59
+
60
+ //Template code:
61
+ $tplFileName= $atts['template'] != 'default'?dirname(__FILE__).'/templates/'.$atts['template'].'.php' : null;
62
+ if ((!empty($tplFileName)) && (is_readable($tplFileName))) {
63
+ $lcpTemplate = true;
64
+ }else{
65
+ $output = '<ul class="lcp_catlist">';//For default ul
66
+ }
67
+
68
+ foreach($catposts as $single):
69
+ //Template idea by Verex
70
+ if($lcpTemplate){
71
+ require($tplFileName);
72
+ } else {
73
+ $output .= '<li><a href="' . get_permalink($single->ID).'">' . $single->post_title . '</a>';
74
+ if($atts['date']=='yes'){
75
+ $output .= ' - ' . get_the_time($atts['dateformat'], $single);//by Verex, great idea!
76
+ }
77
+ if($atts['author']=='yes'){
78
+ $lcp_userdata = get_userdata($single->post_author);
79
+ $output.=" - ".$lcp_userdata->user_nicename . '<br/>';
80
+ }
81
+ if($atts['excerpt']=='yes' && ($single->post_excerpt)){
82
+ $output .= "<p>$single->post_excerpt</p>";
83
+ }
84
+ $output.="</li>";
85
+ }
86
+ endforeach;
87
+ $output .= "</ul>";
88
+ return $output;
89
  }
90
 
91
  function lcp_add_option_page(){
92
+ add_options_page('List Category Posts', 'List Category Posts', 'manage_options','list-category-posts/list_cat_posts_options.php');
93
  }
94
 
95
  //Sidebar Widget:
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.5
6
- Tested up to: 2.7
7
- Stable tag: 0.4.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.
@@ -14,7 +14,7 @@ Usage: [catlist argument1=value1 argument2=value2].
14
 
15
  * Upload listcat directory into you wp-content/plugins/ directory.
16
  * Login to your WordPress Admin menu, go to Plugins, and activate it.
17
- * Add lcp_catlist class into your theme’s CSS for custom formatting.
18
  * You can find the List Category Posts widget in your widgets. Hasn't been tested, still in development, but usable.
19
 
20
  **If you're updating List Category Posts from version 0.1**, you must change the code in the pages using it, since it's not backwards compatible. LCP now uses WordPress's shortcode API, in order to allow arguments. You should chang the previous [catlist=ID] to [catlist id=ID].
@@ -50,53 +50,60 @@ The arguments you can use are:
50
 
51
  * 'numberposts' - Number of posts to return. Set to 0 to use the max number of posts per page. Set to -1 to remove the limit. Default: 5. Ex: [catlist name=mycategory numberposts=10]
52
 
53
- * 'date' - Display the date of the post next to the title. Default is 'no', use date=yes to activate it.
54
 
55
- * 'author' - Display the author of the post next to the title. Default is 'no', use author=yes to activate it.
56
 
57
- You can customize the way List Category Posts shows the posts in your CSS by editing "lcp_catlist".
 
 
 
 
58
 
59
  Since version 0.2, List Category Posts includes a sidebar widget. It works pretty much the same as the plugin itself.
60
 
61
  Your comments and feedback are welcome at: http://picandocodigo.net/programacion/wordpress/list-category-posts-wordpress-plugin-english/
62
 
63
- List category posts was written initially with Geany - http://geany.uvena.de/.
64
- Now it's being written with GNU Emacs - http://www.gnu.org/software/emacs/
 
 
 
65
 
66
- **Changelog**
67
 
68
- **0.4.1**
 
 
 
 
 
 
69
 
70
  * Fixed some code to enable PHP 4 compatibility. Shouldn't hosting services update to PHP 5?
71
 
72
- **0.4**
73
 
74
  * Added 'date' parameter. Now you can show the post's date when listed.
75
-
76
  * Added 'author' parameter. You can also show the post's author.
77
-
78
  * Sidebar Widget now allows you to add a title in h2 tags.
79
-
80
  * Changed some variable names, to keep better compatibility with other plugins/wordpress variables.
81
-
82
  * Tested with Wordpress 2.7.
83
 
84
- **0.3**
85
 
86
  * Broke backwards compatibility. Users of version 0.1 should update their pages and posts for the new shortcode formatting.
87
-
88
  * Option to pass arguments to the plugin, in order to use name of category instead of ID, orderby, order and number of posts are passed through parameters.
89
 
90
- **0.2**
91
 
92
  * Added experimental sidebar widget (use at your own risk, not ready for prime-time yet since it hasn't been tested :P )
93
 
94
- **0.1.1**
95
 
96
  * Fixed major bug, which gave 404 error when trying to use "Options" page.
97
 
98
- **0.1**
99
 
100
  * Option page to limit number of posts.
101
-
102
  * Working using [category=ID] for posts and pages, with several categories support.
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.5
6
+ Tested up to: 2.8.4
7
+ Stable tag: 0.5
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.
14
 
15
  * Upload listcat directory into you wp-content/plugins/ directory.
16
  * Login to your WordPress Admin menu, go to Plugins, and activate it.
17
+ * Add "lcp_catlist" class into your theme’s CSS for custom formatting, or create a new php file in templates directory and use it as a parameter.
18
  * You can find the List Category Posts widget in your widgets. Hasn't been tested, still in development, but usable.
19
 
20
  **If you're updating List Category Posts from version 0.1**, you must change the code in the pages using it, since it's not backwards compatible. LCP now uses WordPress's shortcode API, in order to allow arguments. You should chang the previous [catlist=ID] to [catlist id=ID].
50
 
51
  * 'numberposts' - Number of posts to return. Set to 0 to use the max number of posts per page. Set to -1 to remove the limit. Default: 5. Ex: [catlist name=mycategory numberposts=10]
52
 
53
+ * 'date' - Display post's date next to the title. Default is 'no', use date=yes to activate it.
54
 
55
+ * 'author' - Display the post's author next to the title. Default is 'no', use author=yes to activate it.
56
 
57
+ * 'dateformat' - Format of the date output. Default is get_option('date_format')
58
+
59
+ * '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: 'lcp_catlist'
60
+
61
+ * 'excerpt' - Display the post's excerpt. Default is 'no', use excerpt=yes to activate it.
62
 
63
  Since version 0.2, List Category Posts includes a sidebar widget. It works pretty much the same as the plugin itself.
64
 
65
  Your comments and feedback are welcome at: http://picandocodigo.net/programacion/wordpress/list-category-posts-wordpress-plugin-english/
66
 
67
+ **New Code is welcome** :D
68
+
69
+ == Frequently Asked Questions ==
70
+ Got any question?
71
+ http://picandocodigo.net/programacion/wordpress/list-category-posts-wordpress-plugin-english/
72
 
73
+ == Changelog ==
74
 
75
+ = 0.5 =
76
+ * Readme.txt validation.
77
+ * Added 'excerpt' parameter. You can now show the excerpt for each post.
78
+ * Added 'dateformat' parameter. Format of the date output. Default is get_option('date_format') - by Verex
79
+ * Added 'template' parameter. Now you can choose template for output of the plugin. 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 -by Verex
80
+
81
+ = 0.4.1 =
82
 
83
  * Fixed some code to enable PHP 4 compatibility. Shouldn't hosting services update to PHP 5?
84
 
85
+ = 0.4 =
86
 
87
  * Added 'date' parameter. Now you can show the post's date when listed.
 
88
  * Added 'author' parameter. You can also show the post's author.
 
89
  * Sidebar Widget now allows you to add a title in h2 tags.
 
90
  * Changed some variable names, to keep better compatibility with other plugins/wordpress variables.
 
91
  * Tested with Wordpress 2.7.
92
 
93
+ = 0.3 =
94
 
95
  * Broke backwards compatibility. Users of version 0.1 should update their pages and posts for the new shortcode formatting.
 
96
  * Option to pass arguments to the plugin, in order to use name of category instead of ID, orderby, order and number of posts are passed through parameters.
97
 
98
+ = 0.2 =
99
 
100
  * Added experimental sidebar widget (use at your own risk, not ready for prime-time yet since it hasn't been tested :P )
101
 
102
+ = 0.1.1 =
103
 
104
  * Fixed major bug, which gave 404 error when trying to use "Options" page.
105
 
106
+ = 0.1 =
107
 
108
  * Option page to limit number of posts.
 
109
  * Working using [category=ID] for posts and pages, with several categories support.
templates/default.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: List Category Posts - Template
4
+ Plugin URI: http://picandocodigo.net/programacion/wordpress/list-category-posts-wordpress-plugin-english/
5
+ Description: Template file for List Category Post Plugin for Wordpress which is used by plugin by argument template=value.php
6
+ Version: 0.0.2
7
+ Author: Radek Uldrych & Fernando Briano
8
+ Author URI: http://picandocodigo.net http://radoviny.net
9
+ */
10
+
11
+ /* Copyright 2009 Radek Uldrych (email : verex@centrum.cz), Fernando Briano (http://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
+ $output .= "<li><a href='".get_permalink($single->ID)."'>".$single->post_title."</a>";
28
+ //Style for date:
29
+ if($atts['date']=='yes'){
30
+ $output.=" - ".get_the_time($atts['dateformat'], $single);
31
+ }
32
+ //Show author?
33
+ if($atts['author']=='yes'){
34
+ $lcp_userdata = get_userdata($single->post_author);
35
+ $output.=" - ".$lcp_userdata->user_nicename;
36
+ }
37
+ //Show excerpt?
38
+ if($atts['excerpt']=='yes' && ($single->post_excerpt)){
39
+ $output .= "<p>$single->post_excerpt</p>";
40
+ }
41
+ $output.="</li>";
42
+ ?>