List category posts - Version 0.3

Version Description

Download this release

Release Info

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

Code changes from version 0.1.1 to 0.3

lcp_widget_form.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $options = get_option("lcp_widget_options");
3
+ if (!is_array( $options)){
4
+ $options = array(
5
+ 'lcp_widget_categoryid' => '1',
6
+ 'lcp_widget_limit' => '5',
7
+ 'lcp_widget_orderby' => 'date',
8
+ 'lcp_widget_order' => 'asc'
9
+ );
10
+ }
11
+ ?>
12
+ <p>Category:<br/>
13
+ <select name="lcp_widget_categoryid">
14
+ <?php
15
+ $categories= get_categories();
16
+ foreach ($categories as $cat) {
17
+ $option = '<option value="'.$cat->cat_ID.'">';
18
+ $option .= $cat->cat_name;
19
+ $option .= '</option>';
20
+ echo $option;
21
+ }
22
+ ?>
23
+ </select></p>
24
+
25
+ <p>Number of posts:<br/>
26
+ <input type='text' name='lcp_widget_limit'></p>
27
+ <p>Order By:<br/>
28
+ <select name='lcp_widget_orderby'>
29
+ <option value='date'>Date</option>
30
+ <option value='title'>Post title</option>
31
+ <option value='author'>Author</option>
32
+ <option value='rand'>Random</option>
33
+ </select></p>
34
+ <p>Order:<br/>
35
+ <select name='lcp_widget_order'>
36
+ <option value='desc'>Descending</option>
37
+ <option value='asc'>Ascending</option>
38
+ </select></p>
39
+
40
+ <?php
41
+ if ($_POST['lcp_widget_submit']){
42
+ $options['lcp_widget_categoryid']=htmlspecialchars($_POST['lcp_widget_categoryid']);
43
+ $options['lcp_widget_limit']=htmlspecialchars($_POST['lcp_widget_limit']);
44
+ $options['lcp_widget_orderby']=htmlspecialchars($_POST['lcp_widget_orderby']);
45
+ $options['lcp_widget_order']=htmlspecialchars($_POST['lcp_widget_order']);
46
+
47
+ update_option("lcp_widget_categoryid", $options['lcp_widget_categoryid']);
48
+ update_option("lcp_widget_limit", $options['lcp_widget_limit']);
49
+ update_option("lcp_widget_orderby", $options['lcp_widget_orderby']);
50
+ update_option("lcp_widget_order", $options['lcp_widget_order']);
51
+ }
52
+ ?>
53
+ <input type="hidden" id="lcp_widget_submit" name="lcp_widget_submit" value="1" />
list_cat_posts.php CHANGED
@@ -1,9 +1,9 @@
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 is a simple WordPress plugin which allows you to list some posts from a category into a post/page using [catlist=ID], where ID stands for the Category Id. You can list several categories on the same page/post. You can use [catlist=ID] as many times as needed with different Id’s. You may also define a limit of posts to show. Great to use WordPress as a CMS, and create pages with several categories posts. <br/><br/>Inspired by Category Page: http://wordpress.org/extend/plugins/page2cat/<br/>Category Page is a good plugin, but too complicated and big for what I needed. I just needed to list posts from a certain category, and be able to use several category id's to list on one page.
6
- Version: 0.1.1
7
  Author: Fernando Briano
8
  Author URI: http://picandocodigo.net/wordpress/
9
  */
@@ -25,38 +25,41 @@ 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
- /*The following code is based on code from: Category Page: http://wordpress.org/extend/plugins/page2cat/
29
- * Pixline - http://pixline.net/ */
30
- // filter the content of a page, check for tag and replace it with a list of posts in the requested category.
31
- // function heavily inspired from Alex Rabe NextGen Gallery's nggfunctions.php.
32
- function list_category_posts($content){
33
- global $post;
34
- if ( stristr( $content, '[catlist' )) {
35
- $search = "@(?:<p>)*\s*\[catlist\s*=\s*(\w+|^\+)\]\s*(?:</p>)*@i";
36
- if (preg_match_all($search, $content, $matches)) {
37
- if (is_array($matches)) {
38
- $limit = get_option('lcp_limit');
39
- foreach ($matches[1] as $key =>$v0) {
40
- $output = "<ul class='lcp_catlist'>";
41
- $catposts = get_posts('category='.$v0."&numberposts=".$limit);
42
- foreach($catposts as $single):
43
- $output .= "<li><a href='".get_permalink($single->ID)."'>".$single->post_title."</a></li>";
44
- endforeach;
45
- $search = $matches[0][$key];
46
- $output .= "</ul>";
47
- $replace= $output;
48
- $content= str_replace ($search, $replace, $content);
49
- }
50
- }
51
- }
52
  }
53
- return $content;
 
 
 
 
 
54
  }
55
 
56
  function lcp_add_option_page(){
57
- add_options_page('Category List', 'Category List', 'manage_options','list-category-posts/list_cat_posts_options.php');
58
  }
59
 
60
- add_filter('the_content','list_category_posts');
61
- add_action('admin_head', 'lcp_add_option_page');
 
 
 
62
  ?>
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.3
7
  Author: Fernando Briano
8
  Author URI: http://picandocodigo.net/wordpress/
9
  */
25
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
  */
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
+ ), $atts);
37
+ return list_category_posts($atts);
38
+ }
39
+ add_shortcode('catlist', 'catlist_func');
40
+
41
+ function list_category_posts($atts){
42
+ $output = "<ul class='lcp_catlist'>";
43
+ if($atts['name']!='default' && $atts['id']!='0'){
44
+ $category='category_name='.$atts['name'];
45
+ }else{
46
+ $category='category='.$atts['id'];
 
 
 
 
 
47
  }
48
+ $catposts=get_posts($category.'&numberposts='.$atts['numberposts'].'&orderby='.$atts['orderby'].'&order='.$atts['order']);
49
+ foreach($catposts as $single):
50
+ $output .= "<li><a href='".get_permalink($single->ID)."'>".$single->post_title."</a></li>";
51
+ endforeach;
52
+ $output .= "</ul>";
53
+ return $output;
54
  }
55
 
56
  function lcp_add_option_page(){
57
+ add_options_page('List Category Posts', 'List Category Posts', 'manage_options','list-category-posts/list_cat_posts_options.php');
58
  }
59
 
60
+ //Sidebar Widget:
61
+ include('list_cat_posts_widget.php');
62
+ //Filters and actions:
63
+ add_action('plugins_loaded', 'lcp_load_widget');
64
+
65
  ?>
list_cat_posts_options.php DELETED
@@ -1,21 +0,0 @@
1
- <form method="post" action="options.php">
2
- <?php
3
- wp_nonce_field('update-options');
4
- $limit=get_option('lcp_limit');
5
- if($limit=="")
6
- $limit=5
7
- ?>
8
- <table>
9
- <tr>
10
- <td>Posts limit:
11
- </td>
12
- <td><input type="text" name="lcp_limit" value="<?php echo $limit; ?>">
13
- </td>
14
- </tr>
15
- </table>
16
- <input type="hidden" name="action" value="update" />
17
- <input type="hidden" name="page_options" value="lcp_limit" />
18
- <p class="submit">
19
- <input type="submit" name="Submit" value="<?php _e('Save Changes') ?>" />
20
- </p>
21
- </form>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
list_cat_posts_widget.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ //Sidebar Widget file
3
+
4
+ function lcp_load_widget() {
5
+ if (function_exists('register_sidebar_widget')) {
6
+ register_sidebar_widget('List category posts', 'lcp_widget');
7
+ register_widget_control('List category posts', 'lcp_widget_options', 300, 200 );
8
+ }
9
+ }
10
+
11
+ function lcp_widget(){//Display
12
+ $id = get_option("lcp_widget_categoryid");
13
+ $limit = get_option("lcp_widget_limit");
14
+ $orderby=get_option("lcp_widget_orderby");
15
+ $order=get_option("lcp_widget_order");
16
+ $result = '<ul class="lcp_catlist">';
17
+ $catposts = get_posts('category='.$id.'&numberposts='.$limit.'&orderby='.$orderby.'&order='.$order);
18
+ foreach($catposts as $single):
19
+ $result.='<li><a href="'.get_permalink($single->ID).'">'.$single->post_title.'</a></li>';
20
+ endforeach;
21
+ $result .= "</ul>";
22
+ echo $result;
23
+ }
24
+
25
+ function lcp_widget_options(){
26
+ include('lcp_widget_form.php');
27
+ }
28
+
29
+ ?>
readme.txt CHANGED
@@ -2,35 +2,75 @@
2
  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.0
6
  Tested up to: 2.6
7
- Stable tag: 0.1.1
8
 
9
  == Description ==
10
- List Category Posts is a simple WordPress plugin which allows you to list some posts from a category into a post/page using [catlist=ID], where ID stands for the Category Id. You can list several categories on the same page/post. You can use [catlist=ID] as many times as needed with different Id’s. You may also define a limit of posts to show.
11
- Great to use WordPress as a CMS, and create pages with several categories posts.
12
 
13
- Inspired by Category Page: http://wordpress.org/extend/plugins/page2cat/
14
- Category Page is a good plugin, but too complicated and big for what I needed. I just needed to list posts from a certain category, and be able to use several category id's to list on one page.
15
 
16
- List category posts was written with Geany - http://geany.uvena.de/
 
 
 
17
 
18
- ==Installation==
19
 
20
- * Upload listcat directory into you wp-content/plugins/ directory.
21
- * Login to your WordPress Admin menu, go to Plugins, and activate it.
22
- * On Settings / Category List, input the post limit (how many posts you want it to display). Default is 5.
23
- * Add “lcp_catlist” class into your theme’s CSS for custom formatting.
24
 
25
- ==Usage==
 
 
 
 
26
 
27
- When writing a post/page, use [catlist=ID] where ID is the Id for a specific category. You can change the way List Category Posts shows the posts in your CSS by editing "lcp_catlist". The generated code is: <ul class="lcp_catlist">, and a <li> for each post in the category.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
- ==Other notes==
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
  0.1.1
32
- * Fixed major bug, which gave 404 error when trying to use "Options" page.
33
 
34
  0.1
35
- * Option page to limit number of posts.
36
- * Working using [category=ID] for posts and pages, with several categories support.
2
  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.6
7
+ Stable tag: 0.3
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.
11
+ Usage: [catlist argument1=value1 argument2=value2].
12
 
13
+ ==Installation==
 
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].
21
 
22
+ ==Other notes==
 
 
 
23
 
24
+ **Usage**
25
+ The arguments you can use are:
26
+ 'name' - To display posts from a category using the category's name. Ex: [catlist name=mycategory]
27
+ 'id' - To display posts from a category using the category's id. Ex: [catlist id=24]
28
+ If you use both arguments (wrong!), List Category Posts will show the posts from the category in 'name'.
29
 
30
+ 'orderby' - To customize the order. Valid values are:
31
+ * 'author' - Sort by the numeric author IDs.
32
+ * 'category' - Sort by the numeric category IDs.
33
+ * 'content' - Sort by content.
34
+ * 'date' - Sort by creation date.
35
+ * 'ID' - Sort by numeric post ID.
36
+ * 'menu_order' - Sort by the menu order. Only useful with pages.
37
+ * 'mime_type' - Sort by MIME type. Only useful with attachments.
38
+ * 'modified' - Sort by last modified date.
39
+ * 'name' - Sort by stub.
40
+ * 'parent' - Sort by parent ID.
41
+ * 'password' - Sort by password.
42
+ * 'rand' - Randomly sort results.
43
+ * 'status' - Sort by status.
44
+ * 'title' - Sort by title.
45
+ * 'type' - Sort by type.
46
+ Ex: [catlist name=mycategory orderby=date]
47
 
48
+ 'order' - How to sort 'orderby'. Valid values are:
49
+ * 'ASC' - Ascending (lowest to highest).
50
+ * 'DESC' - Descending (highest to lowest).
51
+ Ex: [catlist name=mycategory orderby=title order=asc]
52
+
53
+ '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
54
+ Ex: [catlist name=mycategory numberposts=10]
55
+
56
+ You can customize the way List Category Posts shows the posts in your CSS by editing "lcp_catlist".
57
+
58
+ Since version 0.2, List Category Posts includes a sidebar widget. This is still in development, since I dedicated more time to the arguments in [catlist]. It does work, but you're welcome to test it and comment your feedback at: http://picandocodigo.net/programacion/wordpress/list-category-posts-wordpress-plugin-english/
59
+
60
+ List category posts was written with Geany - http://geany.uvena.de/
61
+
62
+ **Changelog**
63
+
64
+ 0.3
65
+ * Broke backwards compatibility. Users of version 0.1 should update their pages and posts for the new shortcode formatting.
66
+ * 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.
67
+
68
+ 0.2
69
+ * Added experimental sidebar widget (use at your own risk, not ready for prime-time yet since it hasn't been tested :P )
70
 
71
  0.1.1
72
+ * Fixed major bug, which gave 404 error when trying to use "Options" page.
73
 
74
  0.1
75
+ * Option page to limit number of posts.
76
+ * Working using [category=ID] for posts and pages, with several categories support.