Version Description
- Changed STYLESHEETPATH to TEMPLATEPATH to point to the parent theme.
- Added support to display custom fields. (http://picod.net/wp03)
- Tested with WordPress 3.1.
Download this release
Release Info
Developer | fernandobt |
Plugin | List category posts |
Version | 0.16 |
Comparing to | |
See all releases |
Code changes from version 0.15.1 to 0.16
- lcp_widget_form.php +14 -9
- list_cat_posts.php +57 -15
- readme.txt +11 -3
- templates/default.php +3 -5
lcp_widget_form.php
CHANGED
@@ -44,13 +44,15 @@ $showexcerpt = strip_tags($instance['excerpt']);
|
|
44 |
//var_dump($instance);
|
45 |
?>
|
46 |
|
47 |
-
<p><label for="<?php echo $this->get_field_id('title'); ?>">
|
|
|
48 |
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>"
|
49 |
name="<?php echo $this->get_field_name('title'); ?>" type="text"
|
50 |
value="<?php echo attribute_escape($title); ?>" />
|
51 |
-
</
|
52 |
|
53 |
-
<p><label for="<?php echo $this->get_field_id('categoryid'); ?>">
|
|
|
54 |
<select id="<?php echo $this->get_field_id('categoryid'); ?>" name="<?php echo $this->get_field_name('categoryid'); ?>">
|
55 |
<?php
|
56 |
$categories= get_categories();
|
@@ -67,11 +69,12 @@ $showexcerpt = strip_tags($instance['excerpt']);
|
|
67 |
?>
|
68 |
</select></p>
|
69 |
|
70 |
-
<p><label for="<?php echo $this->get_field_id('limit'); ?>"
|
|
|
71 |
<input size="2" id="<?php echo $this->get_field_id('limit'); ?>"
|
72 |
name="<?php echo $this->get_field_name('limit'); ?>" type="text"
|
73 |
value="<?php echo attribute_escape($limit); ?>" />
|
74 |
-
</
|
75 |
|
76 |
<p><label for="<?php echo $this->get_field_id('offset'); ?>">Offset: <br/>
|
77 |
<input size="2" id="<?php echo $this->get_field_id('offset'); ?>"
|
@@ -79,21 +82,23 @@ $showexcerpt = strip_tags($instance['excerpt']);
|
|
79 |
value="<?php echo attribute_escape($offset); ?>" />
|
80 |
</label></p>
|
81 |
|
82 |
-
<p><label for="<?php echo $this->get_field_id('order'); ?>">
|
|
|
83 |
<select id="<?php echo $this->get_field_id('orderby'); ?>"
|
84 |
name="<?php echo $this->get_field_name('orderby'); ?>" type="text" />
|
85 |
<option value='date'>Date</option>
|
86 |
<option value='title'>Post title</option>
|
87 |
<option value='author'>Author</option>
|
88 |
<option value='rand'>Random</option>
|
89 |
-
</select
|
|
|
90 |
|
91 |
-
<p><label for="<?php echo $this->get_field_id('order'); ?>">Order: <br/>
|
92 |
<select id="<?php echo $this->get_field_id('order'); ?>"
|
93 |
name="<?php echo $this->get_field_name('order'); ?>" type="text" />
|
94 |
<option value='desc'>Descending</option>
|
95 |
<option value='asc'>Ascending</option>
|
96 |
-
</
|
97 |
|
98 |
<p><label for="<?php echo $this->get_field_id('exclude'); ?>">Exclude categories (id's): <br/>
|
99 |
<input id="<?php echo $this->get_field_id('exclude'); ?>"
|
44 |
//var_dump($instance);
|
45 |
?>
|
46 |
|
47 |
+
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e("Title")?></label>
|
48 |
+
<br/>
|
49 |
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>"
|
50 |
name="<?php echo $this->get_field_name('title'); ?>" type="text"
|
51 |
value="<?php echo attribute_escape($title); ?>" />
|
52 |
+
</p>
|
53 |
|
54 |
+
<p><label for="<?php echo $this->get_field_id('categoryid'); ?>"><?php _e("Category")?></label>
|
55 |
+
<br/>
|
56 |
<select id="<?php echo $this->get_field_id('categoryid'); ?>" name="<?php echo $this->get_field_name('categoryid'); ?>">
|
57 |
<?php
|
58 |
$categories= get_categories();
|
69 |
?>
|
70 |
</select></p>
|
71 |
|
72 |
+
<p><label for="<?php echo $this->get_field_id('limit'); ?>"><?php _e("Number of posts")?></label>
|
73 |
+
<br/>
|
74 |
<input size="2" id="<?php echo $this->get_field_id('limit'); ?>"
|
75 |
name="<?php echo $this->get_field_name('limit'); ?>" type="text"
|
76 |
value="<?php echo attribute_escape($limit); ?>" />
|
77 |
+
</p>
|
78 |
|
79 |
<p><label for="<?php echo $this->get_field_id('offset'); ?>">Offset: <br/>
|
80 |
<input size="2" id="<?php echo $this->get_field_id('offset'); ?>"
|
82 |
value="<?php echo attribute_escape($offset); ?>" />
|
83 |
</label></p>
|
84 |
|
85 |
+
<p><label for="<?php echo $this->get_field_id('order'); ?>"><?php __("Order")?></label>
|
86 |
+
<br/>
|
87 |
<select id="<?php echo $this->get_field_id('orderby'); ?>"
|
88 |
name="<?php echo $this->get_field_name('orderby'); ?>" type="text" />
|
89 |
<option value='date'>Date</option>
|
90 |
<option value='title'>Post title</option>
|
91 |
<option value='author'>Author</option>
|
92 |
<option value='rand'>Random</option>
|
93 |
+
</select>
|
94 |
+
</p>
|
95 |
|
96 |
+
<p><label for="<?php echo $this->get_field_id('order'); ?>">Order: </select>g<br/>
|
97 |
<select id="<?php echo $this->get_field_id('order'); ?>"
|
98 |
name="<?php echo $this->get_field_name('order'); ?>" type="text" />
|
99 |
<option value='desc'>Descending</option>
|
100 |
<option value='asc'>Ascending</option>
|
101 |
+
</p>
|
102 |
|
103 |
<p><label for="<?php echo $this->get_field_id('exclude'); ?>">Exclude categories (id's): <br/>
|
104 |
<input id="<?php echo $this->get_field_id('exclude'); ?>"
|
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 |
*/
|
@@ -58,7 +58,8 @@ function catlist_func($atts, $content = null) {
|
|
58 |
'post_parent' => '0',
|
59 |
'class' => 'lcp_catlist',
|
60 |
'customfield_name' => '',
|
61 |
-
'customfield_value' =>''
|
|
|
62 |
), $atts);
|
63 |
return list_category_posts($atts);
|
64 |
}
|
@@ -71,7 +72,7 @@ add_shortcode('catlist', 'catlist_func');
|
|
71 |
* @param array $atts
|
72 |
*/
|
73 |
function list_category_posts($atts){
|
74 |
-
$lcp_category_id = $atts['id'];
|
75 |
$lcp_category_name = $atts['name'];
|
76 |
|
77 |
//Get the category posts:
|
@@ -90,7 +91,7 @@ function list_category_posts($atts){
|
|
90 |
$tplFileName = null;
|
91 |
$possibleTemplates = array(
|
92 |
// File locations lower in list override others
|
93 |
-
|
94 |
);
|
95 |
foreach ($possibleTemplates as $key => $file) {
|
96 |
if (is_readable($file)) {
|
@@ -113,17 +114,15 @@ function list_category_posts($atts){
|
|
113 |
}
|
114 |
|
115 |
/**
|
116 |
-
* Get the categories
|
117 |
* @param string $lcp_category_id
|
118 |
* @param string $lcp_category_name
|
119 |
*/
|
120 |
function lcp_category($lcp_category_id, $lcp_category_name, $atts){
|
121 |
if($lcp_category_name != 'default' && $lcp_category_id == '0'){
|
122 |
$lcp_category = 'category_name=' . $atts['name'];
|
123 |
-
$category_id = get_cat_ID($atts['name']);
|
124 |
}else{
|
125 |
-
$lcp_category = 'cat=' . $
|
126 |
-
$category_id = $atts['id'];
|
127 |
}
|
128 |
|
129 |
//Build the query for get_posts()
|
@@ -148,7 +147,6 @@ function lcp_category($lcp_category_id, $lcp_category_name, $atts){
|
|
148 |
|
149 |
function lcp_display_post($single, $atts){
|
150 |
$lcp_display_output = '<li><a href="' . get_permalink($single->ID).'">' . $single->post_title . '</a>';
|
151 |
-
|
152 |
if ($atts['comments'] == yes){
|
153 |
$lcp_display_output .= ' (';
|
154 |
$lcp_display_output .= lcp_comments($single);
|
@@ -163,17 +161,22 @@ function lcp_display_post($single, $atts){
|
|
163 |
$lcp_display_output .= " - ".lcp_showauthor($single) . '<br/>';
|
164 |
}
|
165 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
if ($atts['content']=='yes' && $single->post_content){
|
167 |
$lcp_display_output.= lcp_content($single); // line tweaked to output filtered content
|
168 |
}
|
169 |
|
170 |
-
if ($atts['excerpt']
|
171 |
$lcp_display_output .= lcp_excerpt($single);
|
172 |
}
|
173 |
|
174 |
-
if ($atts['thumbnail']=='yes'){
|
175 |
-
$lcp_display_output .= lcp_thumbnail($single);
|
176 |
-
}
|
177 |
$lcp_display_output.="</li>";
|
178 |
return $lcp_display_output;
|
179 |
}
|
@@ -192,7 +195,14 @@ function lcp_showdate($single, $dateformat){
|
|
192 |
}
|
193 |
|
194 |
function lcp_content($single){
|
195 |
-
$lcp_content =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
196 |
$lcp_content = str_replace(']]>', ']]>', $lcp_content); // added to parse shortcodes
|
197 |
return '<p>' . $lcp_content . '</p>';
|
198 |
}
|
@@ -213,7 +223,11 @@ function lcp_excerpt($single){
|
|
213 |
return '<p>' . $lcp_excerpt . '</p>';
|
214 |
}
|
215 |
|
216 |
-
|
|
|
|
|
|
|
|
|
217 |
function lcp_thumbnail($single){
|
218 |
$lcp_thumbnail = '';
|
219 |
if ( has_post_thumbnail($single->ID) ) {
|
@@ -222,9 +236,37 @@ function lcp_thumbnail($single){
|
|
222 |
return $lcp_thumbnail;
|
223 |
}
|
224 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
225 |
/** TODO - These are the todo's for a 1.0 release:
|
226 |
* -Pagination
|
227 |
* -Simplify template system
|
228 |
* -i18n
|
229 |
*/
|
|
|
|
|
230 |
?>
|
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
|
7 |
Author: Fernando Briano
|
8 |
Author URI: http://picandocodigo.net/
|
9 |
*/
|
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 |
}
|
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:
|
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)) {
|
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()
|
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);
|
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); // line tweaked to output filtered content
|
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 |
}
|
195 |
}
|
196 |
|
197 |
function lcp_content($single){
|
198 |
+
$lcp_content = $single->post_content;
|
199 |
+
//Added to stop a post with catlist to display an infinite loop of catlist shortcode parsing
|
200 |
+
if (preg_match("/\[catlist.*\]/", $lcp_content, $regmatch)){
|
201 |
+
foreach ($regmatch as $match){
|
202 |
+
$lcp_content = str_replace($match, '(...)',$lcp_content);
|
203 |
+
}
|
204 |
+
}
|
205 |
+
$lcp_content = apply_filters('the_content', $lcp_content); // added to parse shortcodes
|
206 |
$lcp_content = str_replace(']]>', ']]>', $lcp_content); // added to parse shortcodes
|
207 |
return '<p>' . $lcp_content . '</p>';
|
208 |
}
|
223 |
return '<p>' . $lcp_excerpt . '</p>';
|
224 |
}
|
225 |
|
226 |
+
/**
|
227 |
+
* Get the post Thumbnail
|
228 |
+
* @see http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
|
229 |
+
* @param unknown_type $single
|
230 |
+
*/
|
231 |
function lcp_thumbnail($single){
|
232 |
$lcp_thumbnail = '';
|
233 |
if ( has_post_thumbnail($single->ID) ) {
|
236 |
return $lcp_thumbnail;
|
237 |
}
|
238 |
|
239 |
+
/**
|
240 |
+
* Display custom fields.
|
241 |
+
* @see http://codex.wordpress.org/Function_Reference/get_post_custom
|
242 |
+
* @param string $custom_key
|
243 |
+
* @param int $post_id
|
244 |
+
*/
|
245 |
+
function lcp_display_customfields($custom_key, $post_id){
|
246 |
+
$lcp_customs = '';
|
247 |
+
//Doesn't work for many when having spaces:
|
248 |
+
$custom_key = trim($custom_key);
|
249 |
+
//Create array for many fields:
|
250 |
+
$custom_array = explode(",", $custom_key);
|
251 |
+
//Get post custom fields:
|
252 |
+
$custom_fields = get_post_custom($post_id);
|
253 |
+
//Loop on custom fields and if there's a value, add it:
|
254 |
+
foreach ($custom_array as $something){
|
255 |
+
$my_custom_field = $custom_fields[$something];
|
256 |
+
if (sizeof($my_custom_field) > 0 ):
|
257 |
+
foreach ( $my_custom_field as $key => $value ){
|
258 |
+
$lcp_customs .= $something. " : " . $value . "<br/>";
|
259 |
+
}
|
260 |
+
endif;
|
261 |
+
}
|
262 |
+
return $lcp_customs;
|
263 |
+
}
|
264 |
+
|
265 |
/** TODO - These are the todo's for a 1.0 release:
|
266 |
* -Pagination
|
267 |
* -Simplify template system
|
268 |
* -i18n
|
269 |
*/
|
270 |
+
|
271 |
+
|
272 |
?>
|
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.0.1
|
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.
|
@@ -90,7 +90,9 @@ If you use both arguments (wrong!), List Category Posts will show the posts from
|
|
90 |
|
91 |
* **class** - CSS class for the default UL generated by the plugin.
|
92 |
|
93 |
-
* **custom fields** - To use custom fields, you must specify two values: customfield_name and customfield_value. Using this only show posts that contain a custom field with this name and value. Both parameters must be defined, or neither will work.
|
|
|
|
|
94 |
|
95 |
|
96 |
Your comments and feedback are welcome at: http://foro.picandocodigo.net/categories/list-category-posts
|
@@ -100,7 +102,8 @@ Your comments and feedback are welcome at: http://foro.picandocodigo.net/categor
|
|
100 |
== Frequently Asked Questions ==
|
101 |
* **Instructions** on how to use the plugin: http://foro.picandocodigo.net/discussion/251/list-category-posts-documentation/
|
102 |
* **Template system** how to customize the way the posts are shown: http://foro.picandocodigo.net/discussion/253/list-category-posts-using-templates/
|
103 |
-
* **
|
|
|
104 |
|
105 |
== Upgrade Notice ==
|
106 |
|
@@ -118,6 +121,11 @@ Template system has changed. Custom templates should be stored in wordpress them
|
|
118 |
|
119 |
== Changelog ==
|
120 |
|
|
|
|
|
|
|
|
|
|
|
121 |
= 0.15.1 =
|
122 |
* Fixed a bug with undeclared variable. (Check http://picod.net/walcp, thanks Das!)
|
123 |
|
4 |
Tags: list, categories, posts, cms
|
5 |
Requires at least: 2.8
|
6 |
Tested up to: 3.0.1
|
7 |
+
Stable tag: 0.16
|
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.
|
90 |
|
91 |
* **class** - CSS class for the default UL generated by the plugin.
|
92 |
|
93 |
+
* **custom fields** - To use custom fields, you must specify two values: customfield_name and customfield_value. Using this only show posts that contain a custom field with this name and value. Both parameters must be defined, or neither will work.
|
94 |
+
|
95 |
+
* **customfield_display** - Display custom field(s). You can specify many fields to show, separating them with a coma.
|
96 |
|
97 |
|
98 |
Your comments and feedback are welcome at: http://foro.picandocodigo.net/categories/list-category-posts
|
102 |
== Frequently Asked Questions ==
|
103 |
* **Instructions** on how to use the plugin: http://foro.picandocodigo.net/discussion/251/list-category-posts-documentation/
|
104 |
* **Template system** how to customize the way the posts are shown: http://foro.picandocodigo.net/discussion/253/list-category-posts-using-templates/
|
105 |
+
* **New feature requests** - Contact me on fernando at picandocodigo dot net or check out the forum.
|
106 |
+
* **Support** I've decided to use WordPress Answers (http://meta.wordpress.stackexchange.com/) as the place for support. It's a great place with a large community of WordPress users and developers. Just ask your question with the tag 'plugin-list-category-post'.
|
107 |
|
108 |
== Upgrade Notice ==
|
109 |
|
121 |
|
122 |
== Changelog ==
|
123 |
|
124 |
+
= 0.16 =
|
125 |
+
* Changed STYLESHEETPATH to TEMPLATEPATH to point to the parent theme.
|
126 |
+
* Added support to display custom fields. (http://picod.net/wp03)
|
127 |
+
* Tested with WordPress 3.1.
|
128 |
+
|
129 |
= 0.15.1 =
|
130 |
* Fixed a bug with undeclared variable. (Check http://picod.net/walcp, thanks Das!)
|
131 |
|
templates/default.php
CHANGED
@@ -26,11 +26,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
26 |
*/
|
27 |
|
28 |
//Show category?
|
29 |
-
|
30 |
-
|
31 |
-
}else{
|
32 |
-
$lcp_output = '';
|
33 |
-
}
|
34 |
$lcp_output .= '<ul class="lcp_catlist">';//For default ul
|
35 |
//Posts loop:
|
36 |
foreach($catposts as $single):
|
@@ -52,6 +49,7 @@ foreach($catposts as $single):
|
|
52 |
if($atts['thumbnail']=='yes'){
|
53 |
$lcp_output .= '<div class="lcp_thumbnail">'. lcp_thumbnails($single) . '</div>';
|
54 |
}
|
|
|
55 |
//Show content?
|
56 |
if($atts['content']=='yes' && $single->post_content){
|
57 |
$lcpcontent = apply_filters('the_content', $single->post_content); // added to parse shortcodes
|
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):
|
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
|