Version Description
- Show post thumbnails, should be tested, feedback on styling is welcome. Thanks to Sebastian from http://www.avantix.com.ar/
Download this release
Release Info
Developer | fernandobt |
Plugin | List category posts |
Version | 0.13 |
Comparing to | |
See all releases |
Code changes from version 0.12 to 0.13
- list_cat_posts.php +108 -51
- readme.txt +8 -3
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.
|
7 |
Author: Fernando Briano
|
8 |
Author URI: http://picandocodigo.net/
|
9 |
*/
|
@@ -25,12 +25,17 @@ 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 |
-
|
|
|
|
|
|
|
|
|
|
|
34 |
'id' => '0',
|
35 |
'name' => 'default',
|
36 |
'orderby' => 'date',
|
@@ -47,44 +52,33 @@ function catlist_func($atts, $content=null) {
|
|
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){
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
}
|
65 |
-
|
66 |
-
//Link to the category:
|
67 |
-
$cat_link_string = '';
|
68 |
-
if ($atts['catlink'] == 'yes'){
|
69 |
-
$cat_link = get_category_link($category_id);
|
70 |
-
$cat_data = get_category($category_id);
|
71 |
-
$cat_title = $cat_data->name;
|
72 |
-
$cat_link_string = '<a href=' . $cat_link . ' title="' . $cat_title . '">' . $cat_title . '</a>';
|
73 |
-
}
|
74 |
-
//Build the query for get_posts()
|
75 |
-
$catposts = get_posts($category.'&numberposts=' . $atts['numberposts'] .
|
76 |
-
'&orderby=' . $atts['orderby'] .
|
77 |
-
'&order=' . $atts['order'] .
|
78 |
-
'&exclude=' . $atts['excludeposts'] .
|
79 |
-
'&tag=' . $atts['tags'] .
|
80 |
-
'&offset=' . $atts['offset'] );
|
81 |
//Template code:
|
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) {
|
88 |
if (is_readable($file)) {
|
89 |
$tplFileName = $file;
|
90 |
}
|
@@ -94,41 +88,96 @@ function list_category_posts($atts){
|
|
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 .=
|
103 |
-
if($atts['comments'] == yes){
|
104 |
-
$lcp_output .= ' (' . $single->comment_count . ')';
|
105 |
-
}
|
106 |
-
if($atts['date']=='yes'){
|
107 |
-
$lcp_output .= ' - ' . get_the_time($atts['dateformat'], $single);//by Verex, great idea!
|
108 |
-
}
|
109 |
-
if($atts['author']=='yes'){
|
110 |
-
$lcp_userdata = get_userdata($single->post_author);
|
111 |
-
$lcp_output.=" - ".$lcp_userdata->display_name . '<br/>';
|
112 |
-
}
|
113 |
-
if($atts['content']=='yes' && $single->post_content){
|
114 |
-
$lcp_output.= lcp_content($single); // line tweaked to output filtered content
|
115 |
-
}
|
116 |
-
if($atts['excerpt']!='no' && !($atts['content']=='yes' && $single->post_content) ){
|
117 |
-
$lcp_output .= lcp_excerpt($single);
|
118 |
-
}
|
119 |
-
$lcp_output.="</li>";
|
120 |
endforeach;
|
121 |
$lcp_output .= "</ul>";
|
122 |
}
|
123 |
return $lcp_output;
|
124 |
}
|
125 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
function lcp_content($single){
|
127 |
$lcp_content = apply_filters('the_content', $single->post_content); // added to parse shortcodes
|
128 |
$lcp_content = str_replace(']]>', ']]>', $lcp_content); // added to parse shortcodes
|
129 |
return '<p>' . $lcp_content . '</p>';
|
130 |
}
|
131 |
|
|
|
132 |
function lcp_excerpt($single){
|
133 |
if($single->post_excerpt){
|
134 |
return '<p>' . $single->post_excerpt . '</p>';
|
@@ -144,8 +193,16 @@ function lcp_excerpt($single){
|
|
144 |
return '<p>' . $lcp_excerpt . '</p>';
|
145 |
}
|
146 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
/** TODO - These are the todo's for a 1.0 release:
|
148 |
-
* -Images (preview or thumbnail, whatever, I have to dig into this)
|
149 |
* -Pagination
|
150 |
* -Simplify template system
|
151 |
* -i18n
|
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.13
|
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 |
+
|
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',
|
52 |
'tags' => '',
|
53 |
'content' => 'no',
|
54 |
'catlink' => 'no',
|
55 |
+
'comments' => 'no',
|
56 |
+
'thumbnail' => 'no'
|
57 |
), $atts);
|
58 |
return list_category_posts($atts);
|
59 |
}
|
60 |
|
61 |
+
/* Add the shortcode to WordPress */
|
62 |
add_shortcode('catlist', 'catlist_func');
|
63 |
|
64 |
+
/**
|
65 |
+
* Main function, this is where the flow goes and calls auxiliary functions
|
66 |
+
* @param array $atts
|
67 |
+
*/
|
68 |
function list_category_posts($atts){
|
69 |
+
$lcp_category_id = $atts['id'];
|
70 |
+
$lcp_category_name = $atts['name'];
|
71 |
+
|
72 |
+
//Get the category posts:
|
73 |
+
$catposts = lcp_category($lcp_category_id, $lcp_category_name, $atts);
|
74 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
//Template code:
|
76 |
$tplFileName = null;
|
77 |
$possibleTemplates = array(
|
78 |
// File locations lower in list override others
|
79 |
STYLESHEETPATH.'/list-category-posts/'.$atts['template'].'.php',
|
80 |
);
|
81 |
+
foreach ($possibleTemplates as $key => $file) {
|
82 |
if (is_readable($file)) {
|
83 |
$tplFileName = $file;
|
84 |
}
|
88 |
}else{
|
89 |
if ($cat_link_string != ''){
|
90 |
$lcp_output = '<p><strong>' . $cat_link_string . '</strong></p>';
|
91 |
+
} else {
|
92 |
$lcp_output = '';
|
93 |
}
|
94 |
$lcp_output .= '<ul class="lcp_catlist">';//For default ul
|
95 |
+
foreach ($catposts as $single):
|
96 |
+
$lcp_output .= lcp_display_post($single, $atts);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
endforeach;
|
98 |
$lcp_output .= "</ul>";
|
99 |
}
|
100 |
return $lcp_output;
|
101 |
}
|
102 |
|
103 |
+
/**
|
104 |
+
* Get the categories
|
105 |
+
* @param string $lcp_category_id
|
106 |
+
* @param string $lcp_category_name
|
107 |
+
*/
|
108 |
+
function lcp_category($lcp_category_id, $lcp_category_name, $atts){
|
109 |
+
if($lcp_category_name != 'default' && $lcp_category_id == '0'){
|
110 |
+
$lcp_category = 'category_name=' . $atts['name'];
|
111 |
+
$category_id = get_cat_ID($atts['name']);
|
112 |
+
}else{
|
113 |
+
$lcp_category = 'cat=' . $atts['id'];
|
114 |
+
$category_id = $atts['id'];
|
115 |
+
}
|
116 |
+
|
117 |
+
//Link to the category:
|
118 |
+
$cat_link_string = '';
|
119 |
+
if ($atts['catlink'] == 'yes'){
|
120 |
+
$cat_link = get_category_link($category_id);
|
121 |
+
$cat_data = get_category($category_id);
|
122 |
+
$cat_title = $cat_data->name;
|
123 |
+
$cat_link_string = '<a href="' . $cat_link . '" title="' . $cat_title . '">' . $cat_title . '</a>';
|
124 |
+
}
|
125 |
+
//Build the query for get_posts()
|
126 |
+
$catposts = get_posts($lcp_category.'&numberposts=' . $atts['numberposts'] .
|
127 |
+
'&orderby=' . $atts['orderby'] .
|
128 |
+
'&order=' . $atts['order'] .
|
129 |
+
'&exclude=' . $atts['excludeposts'] .
|
130 |
+
'&tag=' . $atts['tags'] .
|
131 |
+
'&offset=' . $atts['offset'] );
|
132 |
+
return $catposts;
|
133 |
+
}
|
134 |
+
|
135 |
+
function lcp_display_post($single, $atts){
|
136 |
+
$lcp_output .= '<li><a href="' . get_permalink($single->ID).'">' . $single->post_title . '</a>';
|
137 |
+
if ($atts['comments'] == yes){
|
138 |
+
$lcp_output .= ' (';
|
139 |
+
$lcp_output .= lcp_comments($single);
|
140 |
+
$lcp_output .= ')';
|
141 |
+
}
|
142 |
+
if ($atts['date']=='yes'){
|
143 |
+
$lcp_output .= lcp_showdate($single);
|
144 |
+
}
|
145 |
+
if ($atts['author']=='yes'){
|
146 |
+
$lcp_output .= " - ".lcp_showauthor($single) . '<br/>';
|
147 |
+
}
|
148 |
+
if ($atts['content']=='yes' && $single->post_content){
|
149 |
+
$lcp_output.= lcp_content($single); // line tweaked to output filtered content
|
150 |
+
}
|
151 |
+
if ($atts['excerpt']!='no' && !($atts['content']=='yes' && $single->post_content) ){
|
152 |
+
$lcp_output .= lcp_excerpt($single);
|
153 |
+
}
|
154 |
+
if ($atts['thumbnails']=='yes'){
|
155 |
+
$lcp_output .= lcp_thumbnails($single);
|
156 |
+
}
|
157 |
+
$lcp_output.="</li>";
|
158 |
+
return $lcp_output;
|
159 |
+
}
|
160 |
+
|
161 |
+
function lcp_comments($single){
|
162 |
+
return $single->comment_count;
|
163 |
+
}
|
164 |
+
|
165 |
+
function lcp_showauthor($single){
|
166 |
+
$lcp_userdata = get_userdata($single->post_author);
|
167 |
+
return $lcp_userdata->display_name;
|
168 |
+
}
|
169 |
+
|
170 |
+
function lcp_showdate($single){
|
171 |
+
return ' - ' . get_the_time($atts['dateformat'], $single);//by Verex, great idea!
|
172 |
+
}
|
173 |
+
|
174 |
function lcp_content($single){
|
175 |
$lcp_content = apply_filters('the_content', $single->post_content); // added to parse shortcodes
|
176 |
$lcp_content = str_replace(']]>', ']]>', $lcp_content); // added to parse shortcodes
|
177 |
return '<p>' . $lcp_content . '</p>';
|
178 |
}
|
179 |
|
180 |
+
|
181 |
function lcp_excerpt($single){
|
182 |
if($single->post_excerpt){
|
183 |
return '<p>' . $single->post_excerpt . '</p>';
|
193 |
return '<p>' . $lcp_excerpt . '</p>';
|
194 |
}
|
195 |
|
196 |
+
|
197 |
+
function lcp_thumbnails($single){
|
198 |
+
$lcp_thumbnails = '';
|
199 |
+
if ( has_post_thumbnail($single->ID) ) {
|
200 |
+
$lcp_thumbnails = get_the_post_thumbnail($single->ID);
|
201 |
+
}
|
202 |
+
return $lcp_thumbnails;
|
203 |
+
}
|
204 |
+
|
205 |
/** TODO - These are the todo's for a 1.0 release:
|
|
|
206 |
* -Pagination
|
207 |
* -Simplify template system
|
208 |
* -i18n
|
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: 3.0
|
7 |
-
Stable tag: 0.
|
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.
|
@@ -67,7 +67,7 @@ If you use both arguments (wrong!), List Category Posts will show the posts from
|
|
67 |
|
68 |
* **author** - Display the post's author next to the title. Default is 'no', use author=yes to activate it.
|
69 |
|
70 |
-
* **dateformat** - Format of the date output. Default is get_option('date_format')
|
71 |
|
72 |
* **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'
|
73 |
|
@@ -83,6 +83,8 @@ If you use both arguments (wrong!), List Category Posts will show the posts from
|
|
83 |
|
84 |
* **comments** - Show comments count for each post. Default is 'no'. Ex: [catlist comments=yes].
|
85 |
|
|
|
|
|
86 |
Your comments and feedback are welcome at: http://foro.picandocodigo.net/viewforum.php?f=28
|
87 |
|
88 |
**New Code is welcome too** :D
|
@@ -105,6 +107,9 @@ Template system has changed. Custom templates should be stored in wordpress them
|
|
105 |
|
106 |
== Changelog ==
|
107 |
|
|
|
|
|
|
|
108 |
= 0.12 =
|
109 |
* Added comments count.
|
110 |
* Updated readme file
|
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.1
|
7 |
+
Stable tag: 0.13
|
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.
|
67 |
|
68 |
* **author** - Display the post's author next to the title. Default is 'no', use author=yes to activate it.
|
69 |
|
70 |
+
* **dateformat** - Format of the date output. Default is get_option('date_format'). Check http://codex.wordpress.org/Formatting_Date_and_Time for possible formats.
|
71 |
|
72 |
* **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'
|
73 |
|
83 |
|
84 |
* **comments** - Show comments count for each post. Default is 'no'. Ex: [catlist comments=yes].
|
85 |
|
86 |
+
* **thumbnails** - Show post thumbnails (http://markjaquith.wordpress.com/2009/12/23/new-in-wordpress-2-9-post-thumbnail-images/). Default is 'no'. Ex: [catlist thumbnails=yes].
|
87 |
+
|
88 |
Your comments and feedback are welcome at: http://foro.picandocodigo.net/viewforum.php?f=28
|
89 |
|
90 |
**New Code is welcome too** :D
|
107 |
|
108 |
== Changelog ==
|
109 |
|
110 |
+
= 0.13 =
|
111 |
+
* Show post thumbnails, should be tested, feedback on styling is welcome. Thanks to Sebastian from http://www.avantix.com.ar/
|
112 |
+
|
113 |
= 0.12 =
|
114 |
* Added comments count.
|
115 |
* Updated readme file
|