Version Description
Note that version 3.0 drops support for Simple Post Thumbnails plugin in favor of WP 2.9's built in post thumbnail functionality.
Download this release
Release Info
Developer | ZephyrWest |
Plugin | Category Posts Widget |
Version | 3.1 |
Comparing to | |
See all releases |
Code changes from version 2.3 to 3.1
- cat-posts.php +106 -29
- readme.txt +45 -23
- screenshot-1.png +0 -0
cat-posts.php
CHANGED
@@ -1,13 +1,24 @@
|
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: Category Posts Widget
|
4 |
-
Plugin URI: http://jameslao.com/2009/
|
5 |
-
Description: Adds a widget that can display
|
6 |
Author: James Lao
|
7 |
-
Version:
|
8 |
Author URI: http://jameslao.com/
|
9 |
*/
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
class CategoryPosts extends WP_Widget {
|
12 |
|
13 |
function CategoryPosts() {
|
@@ -18,9 +29,13 @@ function CategoryPosts() {
|
|
18 |
* Displays category posts widget on blog.
|
19 |
*/
|
20 |
function widget($args, $instance) {
|
21 |
-
global $post
|
|
|
|
|
22 |
extract( $args );
|
23 |
|
|
|
|
|
24 |
// If not title, use the name of the category.
|
25 |
if( !$instance["title"] ) {
|
26 |
$category_info = get_category($instance["cat"]);
|
@@ -29,13 +44,17 @@ function widget($args, $instance) {
|
|
29 |
|
30 |
// Get array of post info.
|
31 |
$cat_posts = new WP_Query("showposts=" . $instance["num"] . "&cat=" . $instance["cat"]);
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
echo $before_widget;
|
34 |
|
35 |
// Widget title
|
36 |
-
|
37 |
echo $before_title;
|
38 |
-
if(
|
39 |
echo '<a href="' . get_category_link($instance["cat"]) . '">' . $instance["title"] . '</a>';
|
40 |
else
|
41 |
echo $instance["title"];
|
@@ -44,35 +63,72 @@ function widget($args, $instance) {
|
|
44 |
// Post list
|
45 |
echo "<ul>\n";
|
46 |
|
47 |
-
while ( $cat_posts->have_posts() )
|
|
|
|
|
48 |
?>
|
49 |
-
<li class=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
<?php if ( $instance['
|
|
|
|
|
60 |
</li>
|
61 |
-
<?php
|
62 |
-
|
63 |
|
64 |
echo "</ul>\n";
|
65 |
|
66 |
echo $after_widget;
|
|
|
|
|
|
|
|
|
67 |
}
|
68 |
|
69 |
/**
|
70 |
* Form processing... Dead simple.
|
71 |
*/
|
72 |
function update($new_instance, $old_instance) {
|
73 |
-
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
return $new_instance;
|
77 |
}
|
78 |
|
@@ -116,22 +172,43 @@ function form($instance) {
|
|
116 |
</label>
|
117 |
</p>
|
118 |
|
119 |
-
<?php if ( function_exists("p75GetThumbnail") ) : ?>
|
120 |
<p>
|
121 |
-
<label for="<?php echo $this->get_field_id("
|
122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
<?php _e( 'Show post thumbnail' ); ?>
|
124 |
</label>
|
125 |
</p>
|
126 |
<p>
|
127 |
<label>
|
128 |
<?php _e('Thumbnail dimensions'); ?>:<br />
|
129 |
-
<label for="<?php echo $this->get_field_id("
|
130 |
-
W: <input class="widefat" style="width:40%;" type="text" id="<?php echo $this->get_field_id("
|
131 |
</label>
|
132 |
|
133 |
-
<label for="<?php echo $this->get_field_id("
|
134 |
-
H: <input class="widefat" style="width:40%;" type="text" id="<?php echo $this->get_field_id("
|
135 |
</label>
|
136 |
</label>
|
137 |
</p>
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: Category Posts Widget
|
4 |
+
Plugin URI: http://jameslao.com/2009/12/30/category-posts-widget-3-0/
|
5 |
+
Description: Adds a widget that can display posts from a single category.
|
6 |
Author: James Lao
|
7 |
+
Version: 3.1
|
8 |
Author URI: http://jameslao.com/
|
9 |
*/
|
10 |
|
11 |
+
// Register thumbnail sizes.
|
12 |
+
if ( function_exists('add_image_size') )
|
13 |
+
{
|
14 |
+
$sizes = get_option('jlao_cat_post_thumb_sizes');
|
15 |
+
if ( $sizes )
|
16 |
+
{
|
17 |
+
foreach ( $sizes as $id=>$size )
|
18 |
+
add_image_size( 'cat_post_thumb_size' . $id, $size[0], $size[1], true );
|
19 |
+
}
|
20 |
+
}
|
21 |
+
|
22 |
class CategoryPosts extends WP_Widget {
|
23 |
|
24 |
function CategoryPosts() {
|
29 |
* Displays category posts widget on blog.
|
30 |
*/
|
31 |
function widget($args, $instance) {
|
32 |
+
global $post;
|
33 |
+
$post_old = $post; // Save the post object.
|
34 |
+
|
35 |
extract( $args );
|
36 |
|
37 |
+
$sizes = get_option('jlao_cat_post_thumb_sizes');
|
38 |
+
|
39 |
// If not title, use the name of the category.
|
40 |
if( !$instance["title"] ) {
|
41 |
$category_info = get_category($instance["cat"]);
|
44 |
|
45 |
// Get array of post info.
|
46 |
$cat_posts = new WP_Query("showposts=" . $instance["num"] . "&cat=" . $instance["cat"]);
|
47 |
+
|
48 |
+
// Excerpt length filter
|
49 |
+
$new_excerpt_length = create_function('$length', "return " . $instance["excerpt_length"] . ";");
|
50 |
+
if ( $instance["excerpt_length"] > 0 )
|
51 |
+
add_filter('excerpt_length', $new_excerpt_length);
|
52 |
|
53 |
echo $before_widget;
|
54 |
|
55 |
// Widget title
|
|
|
56 |
echo $before_title;
|
57 |
+
if( $instance["title_link"] )
|
58 |
echo '<a href="' . get_category_link($instance["cat"]) . '">' . $instance["title"] . '</a>';
|
59 |
else
|
60 |
echo $instance["title"];
|
63 |
// Post list
|
64 |
echo "<ul>\n";
|
65 |
|
66 |
+
while ( $cat_posts->have_posts() )
|
67 |
+
{
|
68 |
+
$cat_posts->the_post();
|
69 |
?>
|
70 |
+
<li class="cat-post-item">
|
71 |
+
<a class="post-title" href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
|
72 |
+
|
73 |
+
<?php
|
74 |
+
if (
|
75 |
+
function_exists('the_post_thumbnail') &&
|
76 |
+
current_theme_supports("post-thumbnails") &&
|
77 |
+
$instance["thumb"] &&
|
78 |
+
has_post_thumbnail()
|
79 |
+
) :
|
80 |
+
?>
|
81 |
+
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
|
82 |
+
<?php the_post_thumbnail( 'cat_post_thumb_size'.$this->id ); ?>
|
83 |
+
</a>
|
84 |
+
<?php endif; ?>
|
85 |
|
86 |
+
<?php if ( $instance['date'] ) : ?>
|
87 |
+
<p class="post-date"><?php the_time("j M Y"); ?></p>
|
88 |
+
<?php endif; ?>
|
89 |
+
|
90 |
+
<?php if ( $instance['excerpt'] ) : ?>
|
91 |
+
<?php the_excerpt(); ?>
|
92 |
+
<?php endif; ?>
|
93 |
+
|
94 |
+
<?php if ( $instance['comment_num'] ) : ?>
|
95 |
+
<p class="comment-num">(<?php comments_number(); ?>)</p>
|
96 |
+
<?php endif; ?>
|
97 |
</li>
|
98 |
+
<?php
|
99 |
+
}
|
100 |
|
101 |
echo "</ul>\n";
|
102 |
|
103 |
echo $after_widget;
|
104 |
+
|
105 |
+
remove_filter('excerpt_length', $new_excerpt_length);
|
106 |
+
|
107 |
+
$post = $post_old; // Restore the post object.
|
108 |
}
|
109 |
|
110 |
/**
|
111 |
* Form processing... Dead simple.
|
112 |
*/
|
113 |
function update($new_instance, $old_instance) {
|
114 |
+
/**
|
115 |
+
* Save the thumbnail dimensions outside so we can
|
116 |
+
* register the sizes easily. We have to do this
|
117 |
+
* because the sizes must registered beforehand
|
118 |
+
* in order for WP to hard crop images (this in
|
119 |
+
* turn is because WP only hard crops on upload).
|
120 |
+
* The code inside the widget is executed only when
|
121 |
+
* the widget is shown so we register the sizes
|
122 |
+
* outside of the widget class.
|
123 |
+
*/
|
124 |
+
if ( function_exists('the_post_thumbnail') )
|
125 |
+
{
|
126 |
+
$sizes = get_option('jlao_cat_post_thumb_sizes');
|
127 |
+
if ( !$sizes ) $sizes = array();
|
128 |
+
$sizes[$this->id] = array($new_instance['thumb_w'], $new_instance['thumb_h']);
|
129 |
+
update_option('jlao_cat_post_thumb_sizes', $sizes);
|
130 |
+
}
|
131 |
+
|
132 |
return $new_instance;
|
133 |
}
|
134 |
|
172 |
</label>
|
173 |
</p>
|
174 |
|
|
|
175 |
<p>
|
176 |
+
<label for="<?php echo $this->get_field_id("excerpt_length"); ?>">
|
177 |
+
<?php _e( 'Excerpt length (in words):' ); ?>
|
178 |
+
</label>
|
179 |
+
<input style="text-align: center;" type="text" id="<?php echo $this->get_field_id("excerpt_length"); ?>" name="<?php echo $this->get_field_name("excerpt_length"); ?>" value="<?php echo $instance["excerpt_length"]; ?>" size="3" />
|
180 |
+
</p>
|
181 |
+
|
182 |
+
<p>
|
183 |
+
<label for="<?php echo $this->get_field_id("comment_num"); ?>">
|
184 |
+
<input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("comment_num"); ?>" name="<?php echo $this->get_field_name("comment_num"); ?>"<?php checked( (bool) $instance["comment_num"], true ); ?> />
|
185 |
+
<?php _e( 'Show number of comments' ); ?>
|
186 |
+
</label>
|
187 |
+
</p>
|
188 |
+
|
189 |
+
<p>
|
190 |
+
<label for="<?php echo $this->get_field_id("date"); ?>">
|
191 |
+
<input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("date"); ?>" name="<?php echo $this->get_field_name("date"); ?>"<?php checked( (bool) $instance["date"], true ); ?> />
|
192 |
+
<?php _e( 'Show post date' ); ?>
|
193 |
+
</label>
|
194 |
+
</p>
|
195 |
+
|
196 |
+
<?php if ( function_exists('the_post_thumbnail') && current_theme_supports("post-thumbnails") ) : ?>
|
197 |
+
<p>
|
198 |
+
<label for="<?php echo $this->get_field_id("thumb"); ?>">
|
199 |
+
<input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("thumb"); ?>" name="<?php echo $this->get_field_name("thumb"); ?>"<?php checked( (bool) $instance["thumb"], true ); ?> />
|
200 |
<?php _e( 'Show post thumbnail' ); ?>
|
201 |
</label>
|
202 |
</p>
|
203 |
<p>
|
204 |
<label>
|
205 |
<?php _e('Thumbnail dimensions'); ?>:<br />
|
206 |
+
<label for="<?php echo $this->get_field_id("thumb_w"); ?>">
|
207 |
+
W: <input class="widefat" style="width:40%;" type="text" id="<?php echo $this->get_field_id("thumb_w"); ?>" name="<?php echo $this->get_field_name("thumb_w"); ?>" value="<?php echo $instance["thumb_w"]; ?>" />
|
208 |
</label>
|
209 |
|
210 |
+
<label for="<?php echo $this->get_field_id("thumb_h"); ?>">
|
211 |
+
H: <input class="widefat" style="width:40%;" type="text" id="<?php echo $this->get_field_id("thumb_h"); ?>" name="<?php echo $this->get_field_name("thumb_h"); ?>" value="<?php echo $instance["thumb_h"]; ?>" />
|
212 |
</label>
|
213 |
</label>
|
214 |
</p>
|
readme.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: James Lao
|
|
3 |
Donate link: http://jameslao.com/
|
4 |
Tags: category, posts, widget
|
5 |
Requires at least: 2.8
|
6 |
-
Tested up to: 2.
|
7 |
-
Stable tag:
|
8 |
|
9 |
Adds a widget that shows the most recent posts in a single category.
|
10 |
|
@@ -13,13 +13,15 @@ Adds a widget that shows the most recent posts in a single category.
|
|
13 |
Category Posts Widget is a light widget designed to do one thing and do it well: display the most recent posts from a certain category.
|
14 |
|
15 |
Features:
|
16 |
-
|
17 |
-
* Support for displaying thumbnail images via
|
18 |
-
*
|
19 |
-
* Set which category the posts should come form
|
20 |
-
*
|
21 |
-
*
|
22 |
-
*
|
|
|
|
|
23 |
|
24 |
== Installation ==
|
25 |
|
@@ -27,18 +29,38 @@ Features:
|
|
27 |
2. Upload it to the plugins folder of your blog.
|
28 |
3. Goto the Plugins section of the WordPress admin and activate the plugin.
|
29 |
4. Goto the Widget tab of the Presentation section and configure the widget.
|
30 |
-
|
31 |
-
==
|
32 |
-
|
33 |
-
2.
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
* Added support for [Simple Post Thumbnails plugin](http://wordpress.org/extend/plugins/simple-post-thumbnails/).
|
3 |
Donate link: http://jameslao.com/
|
4 |
Tags: category, posts, widget
|
5 |
Requires at least: 2.8
|
6 |
+
Tested up to: 2.9
|
7 |
+
Stable tag: 3.1
|
8 |
|
9 |
Adds a widget that shows the most recent posts in a single category.
|
10 |
|
13 |
Category Posts Widget is a light widget designed to do one thing and do it well: display the most recent posts from a certain category.
|
14 |
|
15 |
Features:
|
16 |
+
|
17 |
+
* Support for displaying thumbnail images via WP 2.9's new post thumbnail feature.
|
18 |
+
* Set how many posts to show.
|
19 |
+
* Set which category the posts should come form.
|
20 |
+
* Option to show the post excerpt and how long the excerpt should be.
|
21 |
+
* Option to show the post date.
|
22 |
+
* Option to show the comment count.
|
23 |
+
* Option to make the widget title link to the category page.
|
24 |
+
* Multiple widgets.
|
25 |
|
26 |
== Installation ==
|
27 |
|
29 |
2. Upload it to the plugins folder of your blog.
|
30 |
3. Goto the Plugins section of the WordPress admin and activate the plugin.
|
31 |
4. Goto the Widget tab of the Presentation section and configure the widget.
|
32 |
+
|
33 |
+
== Upgrade Notice ==
|
34 |
+
|
35 |
+
Note that version 3.0 drops support for [Simple Post Thumbnails plugin](http://wordpress.org/extend/plugins/simple-post-thumbnails/) in favor of WP 2.9's built in post thumbnail functionality.
|
36 |
+
|
37 |
+
== Screenshots ==
|
38 |
+
|
39 |
+
1. The widget configuration dialog.
|
40 |
+
|
41 |
+
== Changelog ==
|
42 |
+
|
43 |
+
3.1
|
44 |
+
|
45 |
+
* Fixed a bug in the thumbnail size registration routine.
|
46 |
+
|
47 |
+
3.0
|
48 |
+
|
49 |
+
* Added support for WP 2.9's post thumbnail feature.
|
50 |
+
* Removed support for Simple Post Thumbnails plugin.
|
51 |
+
* Added option to show the post date.
|
52 |
+
* Added option to set the excerpt length.
|
53 |
+
* Added option to show the number of comments.
|
54 |
+
|
55 |
+
2.3
|
56 |
+
|
57 |
+
* Really tried to fix bug where wp_query global was getting over written by manually instantiating a WP_Query object
|
58 |
+
|
59 |
+
2.1
|
60 |
+
|
61 |
+
* Fixed bug where wp_query global was getting over written.
|
62 |
+
|
63 |
+
2.0
|
64 |
+
|
65 |
+
* Updated to use the WP 2.8 widget API.
|
66 |
* Added support for [Simple Post Thumbnails plugin](http://wordpress.org/extend/plugins/simple-post-thumbnails/).
|
screenshot-1.png
ADDED
Binary file
|