Version Description
- Please consider to re-configure the widget as the latest version has numerous changes from previous.
- Version 4.0 uses CSS file for styling the widget in front end.
- Version 3.0 or later version uses WordPress 2.9's built in post thumbnail functionality.
Download this release
Release Info
Developer | mkrdip |
Plugin | Category Posts Widget |
Version | 4.0 |
Comparing to | |
See all releases |
Code changes from version 3.3 to 4.0
- cat-posts.css +46 -0
- cat-posts.php +279 -225
- readme.txt +40 -13
- screenshot-1.png +0 -0
cat-posts.css
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
Default CSS Styles for the Category Posts Widget plugin
|
3 |
+
Version: 4.0
|
4 |
+
*/
|
5 |
+
.cat-post-widget * {
|
6 |
+
margin: 0;
|
7 |
+
padding:0;
|
8 |
+
}
|
9 |
+
.cat-post-widget {
|
10 |
+
font-size: 12px;
|
11 |
+
line-height: 18px;
|
12 |
+
}
|
13 |
+
.cat-post-widget p {
|
14 |
+
margin-bottom: 0;
|
15 |
+
}
|
16 |
+
.cat-post-widget .post-title {
|
17 |
+
font-size: 15px;
|
18 |
+
font-weight: bold;
|
19 |
+
}
|
20 |
+
.cat-post-widget .post-date {
|
21 |
+
font-style: italic;
|
22 |
+
margin-bottom: 0;
|
23 |
+
}
|
24 |
+
.cat-post-widget img {
|
25 |
+
float: left;
|
26 |
+
margin: 5px 10px 0 0;
|
27 |
+
}
|
28 |
+
.cat-post-widget ul li {
|
29 |
+
list-style: none;
|
30 |
+
list-style-type: none;
|
31 |
+
margin: 3px 0;
|
32 |
+
padding: 3px 0;
|
33 |
+
border-bottom: 1px solid #ccc;
|
34 |
+
}
|
35 |
+
.cat-post-widget ul li:last-child {
|
36 |
+
border-bottom: none;
|
37 |
+
}
|
38 |
+
.cat-post-widget .more-link {
|
39 |
+
display: inline;
|
40 |
+
}
|
41 |
+
.cat-post-widget .post-entry {
|
42 |
+
padding: 0 0 5px 0;
|
43 |
+
overflow: hidden;
|
44 |
+
}
|
45 |
+
.cat-post-widget .comment-num {
|
46 |
+
}
|
cat-posts.php
CHANGED
@@ -1,262 +1,316 @@
|
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: Category Posts Widget
|
4 |
-
Plugin URI:
|
5 |
-
Description: Adds a widget that
|
6 |
-
Author:
|
7 |
-
Version:
|
8 |
-
Author URI: http://
|
9 |
*/
|
10 |
|
11 |
-
//
|
12 |
-
if (
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
-
function
|
25 |
-
|
|
|
26 |
}
|
27 |
|
28 |
/**
|
29 |
-
*
|
|
|
|
|
30 |
*/
|
31 |
-
function
|
32 |
-
|
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"]);
|
42 |
-
$instance["title"] = $category_info->name;
|
43 |
-
}
|
44 |
-
|
45 |
-
$valid_sort_orders = array('date', 'title', 'comment_count', 'rand');
|
46 |
-
if ( in_array($instance['sort_by'], $valid_sort_orders) ) {
|
47 |
-
$sort_by = $instance['sort_by'];
|
48 |
-
$sort_order = (bool) $instance['asc_sort_order'] ? 'ASC' : 'DESC';
|
49 |
-
} else {
|
50 |
-
// by default, display latest first
|
51 |
-
$sort_by = 'date';
|
52 |
-
$sort_order = 'DESC';
|
53 |
-
}
|
54 |
-
|
55 |
-
// Get array of post info.
|
56 |
-
$cat_posts = new WP_Query(
|
57 |
-
"showposts=" . $instance["num"] .
|
58 |
-
"&cat=" . $instance["cat"] .
|
59 |
-
"&orderby=" . $sort_by .
|
60 |
-
"&order=" . $sort_order
|
61 |
-
);
|
62 |
-
|
63 |
-
// Excerpt length filter
|
64 |
-
$new_excerpt_length = create_function('$length', "return " . $instance["excerpt_length"] . ";");
|
65 |
-
if ( $instance["excerpt_length"] > 0 )
|
66 |
-
add_filter('excerpt_length', $new_excerpt_length);
|
67 |
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
if( $instance["title_link"] )
|
73 |
-
echo '<a href="' . get_category_link($instance["cat"]) . '">' . $instance["title"] . '</a>';
|
74 |
-
else
|
75 |
-
echo $instance["title"];
|
76 |
-
echo $after_title;
|
77 |
-
|
78 |
-
// Post list
|
79 |
-
echo "<ul>\n";
|
80 |
-
|
81 |
-
while ( $cat_posts->have_posts() )
|
82 |
-
{
|
83 |
-
$cat_posts->the_post();
|
84 |
-
?>
|
85 |
-
<li class="cat-post-item">
|
86 |
-
<a class="post-title" href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
|
87 |
-
|
88 |
-
<?php
|
89 |
-
if (
|
90 |
-
function_exists('the_post_thumbnail') &&
|
91 |
-
current_theme_supports("post-thumbnails") &&
|
92 |
-
$instance["thumb"] &&
|
93 |
-
has_post_thumbnail()
|
94 |
-
) :
|
95 |
-
?>
|
96 |
-
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
|
97 |
-
<?php the_post_thumbnail( 'cat_post_thumb_size'.$this->id ); ?>
|
98 |
-
</a>
|
99 |
-
<?php endif; ?>
|
100 |
-
|
101 |
-
<?php if ( $instance['date'] ) : ?>
|
102 |
-
<p class="post-date"><?php the_time("j M Y"); ?></p>
|
103 |
-
<?php endif; ?>
|
104 |
-
|
105 |
-
<?php if ( $instance['excerpt'] ) : ?>
|
106 |
-
<?php the_excerpt(); ?>
|
107 |
-
<?php endif; ?>
|
108 |
-
|
109 |
-
<?php if ( $instance['comment_num'] ) : ?>
|
110 |
-
<p class="comment-num">(<?php comments_number(); ?>)</p>
|
111 |
-
<?php endif; ?>
|
112 |
-
</li>
|
113 |
-
<?php
|
114 |
}
|
115 |
-
|
116 |
-
echo "</ul>\n";
|
117 |
-
|
118 |
-
echo $after_widget;
|
119 |
-
|
120 |
-
remove_filter('excerpt_length', $new_excerpt_length);
|
121 |
-
|
122 |
-
$post = $post_old; // Restore the post object.
|
123 |
}
|
124 |
|
|
|
|
|
|
|
125 |
/**
|
126 |
-
*
|
|
|
|
|
127 |
*/
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
* in order for WP to hard crop images (this in
|
134 |
-
* turn is because WP only hard crops on upload).
|
135 |
-
* The code inside the widget is executed only when
|
136 |
-
* the widget is shown so we register the sizes
|
137 |
-
* outside of the widget class.
|
138 |
-
*/
|
139 |
-
if ( function_exists('the_post_thumbnail') )
|
140 |
-
{
|
141 |
-
$sizes = get_option('jlao_cat_post_thumb_sizes');
|
142 |
-
if ( !$sizes ) $sizes = array();
|
143 |
-
$sizes[$this->id] = array($new_instance['thumb_w'], $new_instance['thumb_h']);
|
144 |
-
update_option('jlao_cat_post_thumb_sizes', $sizes);
|
145 |
}
|
146 |
-
|
147 |
-
return $new_instance;
|
148 |
-
}
|
149 |
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
?>
|
155 |
-
<p>
|
156 |
-
<label for="<?php echo $this->get_field_id("title"); ?>">
|
157 |
-
<?php _e( 'Title' ); ?>:
|
158 |
-
<input class="widefat" id="<?php echo $this->get_field_id("title"); ?>" name="<?php echo $this->get_field_name("title"); ?>" type="text" value="<?php echo esc_attr($instance["title"]); ?>" />
|
159 |
-
</label>
|
160 |
-
</p>
|
161 |
|
162 |
-
|
163 |
-
<label>
|
164 |
-
<?php _e( 'Category' ); ?>:
|
165 |
-
<?php wp_dropdown_categories( array( 'name' => $this->get_field_name("cat"), 'selected' => $instance["cat"] ) ); ?>
|
166 |
-
</label>
|
167 |
-
</p>
|
168 |
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
|
|
175 |
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
</label>
|
186 |
-
</p>
|
187 |
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
</label>
|
196 |
-
</p>
|
197 |
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
211 |
|
212 |
-
|
213 |
-
<label for="<?php echo $this->get_field_id("excerpt_length"); ?>">
|
214 |
-
<?php _e( 'Excerpt length (in words):' ); ?>
|
215 |
-
</label>
|
216 |
-
<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" />
|
217 |
-
</p>
|
218 |
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
<?php _e( 'Show number of comments' ); ?>
|
223 |
-
</label>
|
224 |
-
</p>
|
225 |
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
232 |
|
233 |
-
|
234 |
-
|
235 |
-
<label for="<?php echo $this->get_field_id("thumb"); ?>">
|
236 |
-
<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 ); ?> />
|
237 |
-
<?php _e( 'Show post thumbnail' ); ?>
|
238 |
-
</label>
|
239 |
-
</p>
|
240 |
-
<p>
|
241 |
-
<label>
|
242 |
-
<?php _e('Thumbnail dimensions'); ?>:<br />
|
243 |
-
<label for="<?php echo $this->get_field_id("thumb_w"); ?>">
|
244 |
-
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"]; ?>" />
|
245 |
-
</label>
|
246 |
|
247 |
-
|
248 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
249 |
</label>
|
250 |
-
</
|
251 |
-
</p>
|
252 |
-
<?php endif; ?>
|
253 |
|
254 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
255 |
|
256 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
257 |
|
258 |
}
|
259 |
|
260 |
add_action( 'widgets_init', create_function('', 'return register_widget("CategoryPosts");') );
|
261 |
-
|
262 |
-
?>
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: Category Posts Widget
|
4 |
+
Plugin URI: https://wordpress.org/plugins/category-posts/
|
5 |
+
Description: Adds a widget that shows the most recent posts from a single category.
|
6 |
+
Author: Mrinal Kanti Roy
|
7 |
+
Version: 4.0
|
8 |
+
Author URI: http://profiles.wordpress.org/mkrdip/
|
9 |
*/
|
10 |
|
11 |
+
// Don't call the file directly
|
12 |
+
if ( !defined( 'ABSPATH' ) ) exit;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
+
/**
|
15 |
+
* Register our styles
|
16 |
+
*
|
17 |
+
* @return void
|
18 |
+
*/
|
19 |
+
add_action( 'wp_enqueue_scripts', 'category_posts_widget_styles' );
|
20 |
|
21 |
+
function category_posts_widget_styles() {
|
22 |
+
wp_register_style( 'category-posts', plugins_url( 'category-posts/cat-posts.css' ) );
|
23 |
+
wp_enqueue_style( 'category-posts' );
|
24 |
}
|
25 |
|
26 |
/**
|
27 |
+
* Register thumbnail sizes.
|
28 |
+
*
|
29 |
+
* @return void
|
30 |
*/
|
31 |
+
function category_posts_add_image_size(){
|
32 |
+
$sizes = get_option('mkrdip_cat_post_thumb_sizes');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
+
if ( $sizes ){
|
35 |
+
foreach ( $sizes as $id=>$size ) {
|
36 |
+
add_image_size( 'cat_post_thumb_size' . $id, $size[0], $size[1], true );
|
37 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
}
|
40 |
|
41 |
+
add_action( 'init', 'category_posts_add_image_size' );
|
42 |
+
|
43 |
+
|
44 |
/**
|
45 |
+
* Category Posts Widget Class
|
46 |
+
*
|
47 |
+
* Shows the single category posts with some configurable options
|
48 |
*/
|
49 |
+
class CategoryPosts extends WP_Widget {
|
50 |
+
|
51 |
+
function CategoryPosts() {
|
52 |
+
$widget_ops = array('classname' => 'cat-post-widget', 'description' => __('List single category posts'));
|
53 |
+
$this->WP_Widget('category-posts', __('Category Posts'), $widget_ops);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
}
|
|
|
|
|
|
|
55 |
|
56 |
+
// Displays category posts widget on blog.
|
57 |
+
function widget($args, $instance) {
|
58 |
+
global $post;
|
59 |
+
$post_old = $post; // Save the post object.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
+
extract( $args );
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
+
$sizes = get_option('mkrdip_cat_post_thumb_sizes');
|
64 |
+
|
65 |
+
// If not title, use the name of the category.
|
66 |
+
if( !$instance["title"] ) {
|
67 |
+
$category_info = get_category($instance["cat"]);
|
68 |
+
$instance["title"] = $category_info->name;
|
69 |
+
}
|
70 |
|
71 |
+
$valid_sort_orders = array('date', 'title', 'comment_count', 'rand');
|
72 |
+
if ( in_array($instance['sort_by'], $valid_sort_orders) ) {
|
73 |
+
$sort_by = $instance['sort_by'];
|
74 |
+
$sort_order = (bool) isset( $instance['asc_sort_order'] ) ? 'ASC' : 'DESC';
|
75 |
+
} else {
|
76 |
+
// by default, display latest first
|
77 |
+
$sort_by = 'date';
|
78 |
+
$sort_order = 'DESC';
|
79 |
+
}
|
|
|
|
|
80 |
|
81 |
+
// Get array of post info.
|
82 |
+
$cat_posts = new WP_Query(
|
83 |
+
"showposts=" . $instance["num"] .
|
84 |
+
"&cat=" . $instance["cat"] .
|
85 |
+
"&orderby=" . $sort_by .
|
86 |
+
"&order=" . $sort_order
|
87 |
+
);
|
|
|
|
|
88 |
|
89 |
+
// Excerpt length filter
|
90 |
+
$new_excerpt_length = create_function('$length', "return " . $instance["excerpt_length"] . ";");
|
91 |
+
if ( $instance["excerpt_length"] > 0 )
|
92 |
+
add_filter('excerpt_length', $new_excerpt_length);
|
93 |
+
|
94 |
+
echo $before_widget;
|
95 |
|
96 |
+
// Widget title
|
97 |
+
echo $before_title;
|
98 |
+
if( isset( $instance["title_link"] ) )
|
99 |
+
echo '<a href="' . get_category_link($instance["cat"]) . '">' . $instance["title"] . '</a>';
|
100 |
+
else
|
101 |
+
echo $instance["title"];
|
102 |
+
echo $after_title;
|
103 |
+
|
104 |
+
// Post list
|
105 |
+
echo "<ul>\n";
|
106 |
+
|
107 |
+
while ( $cat_posts->have_posts() )
|
108 |
+
{
|
109 |
+
$cat_posts->the_post();
|
110 |
+
?>
|
111 |
+
<li class="cat-post-item">
|
112 |
+
<a class="post-title" href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
|
113 |
+
|
114 |
+
|
115 |
+
<?php if ( isset( $instance['date'] ) ) : ?>
|
116 |
+
<p class="post-date"><?php the_time("j M Y"); ?></p>
|
117 |
+
<?php endif; ?>
|
118 |
+
|
119 |
+
<?php
|
120 |
+
if (
|
121 |
+
function_exists('the_post_thumbnail') &&
|
122 |
+
current_theme_supports("post-thumbnails") &&
|
123 |
+
isset( $instance["thumb"] ) &&
|
124 |
+
has_post_thumbnail()
|
125 |
+
) :
|
126 |
+
?>
|
127 |
+
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
|
128 |
+
<?php the_post_thumbnail( 'cat_post_thumb_size'.$this->id ); ?>
|
129 |
+
</a>
|
130 |
+
<?php endif; ?>
|
131 |
+
|
132 |
+
<?php if ( isset( $instance['excerpt'] ) ) : ?>
|
133 |
+
<?php the_excerpt(); ?>
|
134 |
+
<?php endif; ?>
|
135 |
+
|
136 |
+
<?php if ( isset( $instance['comment_num'] ) ) : ?>
|
137 |
+
<p class="comment-num">(<?php comments_number(); ?>)</p>
|
138 |
+
<?php endif; ?>
|
139 |
+
</li>
|
140 |
+
<?php
|
141 |
+
}
|
142 |
|
143 |
+
echo "</ul>\n";
|
|
|
|
|
|
|
|
|
|
|
144 |
|
145 |
+
echo $after_widget;
|
146 |
+
|
147 |
+
remove_filter('excerpt_length', $new_excerpt_length);
|
|
|
|
|
|
|
148 |
|
149 |
+
wp_reset_postdata();
|
150 |
+
|
151 |
+
}
|
152 |
+
|
153 |
+
/**
|
154 |
+
* Update the options
|
155 |
+
*
|
156 |
+
* @param array $new_instance
|
157 |
+
* @param array $old_instance
|
158 |
+
* @return array
|
159 |
+
*/
|
160 |
+
function update($new_instance, $old_instance) {
|
161 |
+
$sizes = get_option('mkrdip_cat_post_thumb_sizes');
|
162 |
+
|
163 |
+
if ( !$sizes ) {
|
164 |
+
$sizes = array();
|
165 |
+
}
|
166 |
|
167 |
+
$sizes[$this->id] = array($new_instance['thumb_w'], $new_instance['thumb_h']);
|
168 |
+
update_option('mkrdip_cat_post_thumb_sizes', $sizes);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
169 |
|
170 |
+
return $new_instance;
|
171 |
+
}
|
172 |
+
|
173 |
+
/**
|
174 |
+
* The widget configuration form back end.
|
175 |
+
*
|
176 |
+
* @param array $instance
|
177 |
+
* @return void
|
178 |
+
*/
|
179 |
+
function form($instance) {
|
180 |
+
$instance = wp_parse_args( ( array ) $instance, array(
|
181 |
+
'title' => __( '' ),
|
182 |
+
'cat' => __( '' ),
|
183 |
+
'num' => __( '' ),
|
184 |
+
'sort_by' => __( '' ),
|
185 |
+
'asc_sort_order' => __( '' ),
|
186 |
+
'title_link' => __( '' ),
|
187 |
+
'excerpt' => __( '' ),
|
188 |
+
'excerpt_length' => __( '' ),
|
189 |
+
'comment_num' => __( '' ),
|
190 |
+
'date' => __( '' ),
|
191 |
+
'thumb' => __( '' ),
|
192 |
+
'thumb_w' => __( '' ),
|
193 |
+
'thumb_h' => __( '' )
|
194 |
+
) );
|
195 |
+
|
196 |
+
$title = $instance['title'];
|
197 |
+
$cat = $instance['cat'];
|
198 |
+
$num = $instance['num'];
|
199 |
+
$sort_by = $instance['sort_by'];
|
200 |
+
$asc_sort_order = $instance['asc_sort_order'];
|
201 |
+
$title_link = $instance['title_link'];
|
202 |
+
$excerpt = $instance['excerpt'];
|
203 |
+
$excerpt_length = $instance['excerpt_length'];
|
204 |
+
$comment_num = $instance['comment_num'];
|
205 |
+
$date = $instance['date'];
|
206 |
+
$thumb = $instance['thumb'];
|
207 |
+
$thumb_w = $instance['thumb_w'];
|
208 |
+
$thumb_h = $instance['thumb_h'];
|
209 |
+
|
210 |
+
?>
|
211 |
+
<p>
|
212 |
+
<label for="<?php echo $this->get_field_id("title"); ?>">
|
213 |
+
<?php _e( 'Title' ); ?>:
|
214 |
+
<input class="widefat" id="<?php echo $this->get_field_id("title"); ?>" name="<?php echo $this->get_field_name("title"); ?>" type="text" value="<?php echo esc_attr($instance["title"]); ?>" />
|
215 |
+
</label>
|
216 |
+
</p>
|
217 |
+
|
218 |
+
<p>
|
219 |
+
<label>
|
220 |
+
<?php _e( 'Category' ); ?>:
|
221 |
+
<?php wp_dropdown_categories( array( 'name' => $this->get_field_name("cat"), 'selected' => $instance["cat"] ) ); ?>
|
222 |
+
</label>
|
223 |
+
</p>
|
224 |
+
|
225 |
+
<p>
|
226 |
+
<label for="<?php echo $this->get_field_id("num"); ?>">
|
227 |
+
<?php _e('Number of posts to show'); ?>:
|
228 |
+
<input style="text-align: center;" id="<?php echo $this->get_field_id("num"); ?>" name="<?php echo $this->get_field_name("num"); ?>" type="text" value="<?php echo absint($instance["num"]); ?>" size='3' />
|
229 |
</label>
|
230 |
+
</p>
|
|
|
|
|
231 |
|
232 |
+
<p>
|
233 |
+
<label for="<?php echo $this->get_field_id("sort_by"); ?>">
|
234 |
+
<?php _e('Sort by'); ?>:
|
235 |
+
<select id="<?php echo $this->get_field_id("sort_by"); ?>" name="<?php echo $this->get_field_name("sort_by"); ?>">
|
236 |
+
<option value="date"<?php selected( $instance["sort_by"], "date" ); ?>>Date</option>
|
237 |
+
<option value="title"<?php selected( $instance["sort_by"], "title" ); ?>>Title</option>
|
238 |
+
<option value="comment_count"<?php selected( $instance["sort_by"], "comment_count" ); ?>>Number of comments</option>
|
239 |
+
<option value="rand"<?php selected( $instance["sort_by"], "rand" ); ?>>Random</option>
|
240 |
+
</select>
|
241 |
+
</label>
|
242 |
+
</p>
|
243 |
+
|
244 |
+
<p>
|
245 |
+
<label for="<?php echo $this->get_field_id("asc_sort_order"); ?>">
|
246 |
+
<input type="checkbox" class="checkbox"
|
247 |
+
id="<?php echo $this->get_field_id("asc_sort_order"); ?>"
|
248 |
+
name="<?php echo $this->get_field_name("asc_sort_order"); ?>"
|
249 |
+
<?php checked( (bool) $instance["asc_sort_order"], true ); ?> />
|
250 |
+
<?php _e( 'Reverse sort order (ascending)' ); ?>
|
251 |
+
</label>
|
252 |
+
</p>
|
253 |
|
254 |
+
<p>
|
255 |
+
<label for="<?php echo $this->get_field_id("title_link"); ?>">
|
256 |
+
<input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("title_link"); ?>" name="<?php echo $this->get_field_name("title_link"); ?>"<?php checked( (bool) $instance["title_link"], true ); ?> />
|
257 |
+
<?php _e( 'Make widget title link' ); ?>
|
258 |
+
</label>
|
259 |
+
</p>
|
260 |
+
|
261 |
+
<p>
|
262 |
+
<label for="<?php echo $this->get_field_id("excerpt"); ?>">
|
263 |
+
<input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("excerpt"); ?>" name="<?php echo $this->get_field_name("excerpt"); ?>"<?php checked( (bool) $instance["excerpt"], true ); ?> />
|
264 |
+
<?php _e( 'Show post excerpt' ); ?>
|
265 |
+
</label>
|
266 |
+
</p>
|
267 |
+
|
268 |
+
<p>
|
269 |
+
<label for="<?php echo $this->get_field_id("excerpt_length"); ?>">
|
270 |
+
<?php _e( 'Excerpt length (in words):' ); ?>
|
271 |
+
</label>
|
272 |
+
<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" />
|
273 |
+
</p>
|
274 |
+
|
275 |
+
<p>
|
276 |
+
<label for="<?php echo $this->get_field_id("comment_num"); ?>">
|
277 |
+
<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 ); ?> />
|
278 |
+
<?php _e( 'Show number of comments' ); ?>
|
279 |
+
</label>
|
280 |
+
</p>
|
281 |
+
|
282 |
+
<p>
|
283 |
+
<label for="<?php echo $this->get_field_id("date"); ?>">
|
284 |
+
<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 ); ?> />
|
285 |
+
<?php _e( 'Show post date' ); ?>
|
286 |
+
</label>
|
287 |
+
</p>
|
288 |
+
|
289 |
+
<?php if ( function_exists('the_post_thumbnail') && current_theme_supports("post-thumbnails") ) : ?>
|
290 |
+
<p>
|
291 |
+
<label for="<?php echo $this->get_field_id("thumb"); ?>">
|
292 |
+
<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 ); ?> />
|
293 |
+
<?php _e( 'Show post thumbnail' ); ?>
|
294 |
+
</label>
|
295 |
+
</p>
|
296 |
+
<p>
|
297 |
+
<label>
|
298 |
+
<?php _e('Thumbnail dimensions (in pixels)'); ?>:<br />
|
299 |
+
<label for="<?php echo $this->get_field_id("thumb_w"); ?>">
|
300 |
+
Width: <input class="widefat" style="width:30%;" 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"]; ?>" />
|
301 |
+
</label>
|
302 |
+
|
303 |
+
<label for="<?php echo $this->get_field_id("thumb_h"); ?>">
|
304 |
+
Height: <input class="widefat" style="width:30%;" 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"]; ?>" />
|
305 |
+
</label>
|
306 |
+
</label>
|
307 |
+
</p>
|
308 |
+
<?php endif; ?>
|
309 |
+
|
310 |
+
<?php
|
311 |
+
|
312 |
+
}
|
313 |
|
314 |
}
|
315 |
|
316 |
add_action( 'widgets_init', create_function('', 'return register_widget("CategoryPosts");') );
|
|
|
|
readme.txt
CHANGED
@@ -1,21 +1,23 @@
|
|
1 |
-
===
|
2 |
-
Contributors:
|
3 |
-
Donate link:
|
4 |
-
Tags: category, posts, widget
|
5 |
Requires at least: 2.8
|
6 |
-
Tested up to:
|
7 |
-
Stable tag:
|
|
|
|
|
8 |
|
9 |
-
Adds a widget that shows the most recent posts
|
10 |
|
11 |
== Description ==
|
12 |
|
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 |
-
*
|
18 |
-
*
|
19 |
* Set how many posts to show.
|
20 |
* Set which category the posts should come form.
|
21 |
* Option to show the post excerpt and how long the excerpt should be.
|
@@ -24,23 +26,48 @@ Features:
|
|
24 |
* Option to make the widget title link to the category page.
|
25 |
* Multiple widgets.
|
26 |
|
|
|
|
|
|
|
|
|
27 |
== Installation ==
|
28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
1. Download the plugin.
|
30 |
2. Upload it to the plugins folder of your blog.
|
31 |
-
3.
|
32 |
-
4.
|
33 |
|
34 |
== Upgrade Notice ==
|
35 |
|
36 |
-
|
|
|
|
|
|
|
37 |
|
38 |
== Screenshots ==
|
39 |
|
40 |
1. The widget configuration dialog.
|
|
|
41 |
|
42 |
== Changelog ==
|
43 |
|
|
|
|
|
|
|
|
|
|
|
44 |
3.3
|
45 |
|
46 |
* Fixed random sort bug.
|
1 |
+
=== Category Posts Widget ===
|
2 |
+
Contributors: mkrdip
|
3 |
+
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=mkrdip%40yahoo%2ecom&lc=US&item_name=Category%20Posts%20Widget&item_number=02¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted
|
4 |
+
Tags: category, posts, widget, single category widget, posts widget, category recent posts
|
5 |
Requires at least: 2.8
|
6 |
+
Tested up to: 4.0
|
7 |
+
Stable tag: 4.0
|
8 |
+
License: GPLv2 or later
|
9 |
+
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
11 |
+
Adds a widget that shows the most recent posts from a single category.
|
12 |
|
13 |
== Description ==
|
14 |
|
15 |
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.
|
16 |
|
17 |
+
= Features =
|
18 |
|
19 |
+
* Option to change ordering of posts.
|
20 |
+
* Option to show post thumbnail & set dimension by width & height.
|
21 |
* Set how many posts to show.
|
22 |
* Set which category the posts should come form.
|
23 |
* Option to show the post excerpt and how long the excerpt should be.
|
26 |
* Option to make the widget title link to the category page.
|
27 |
* Multiple widgets.
|
28 |
|
29 |
+
= Contribute =
|
30 |
+
While using this plugin if you find any bug or any conflict, please submit an issue at
|
31 |
+
[Github](https://github.com/mkrdip/category-posts-widget) (If possible with a pull request).
|
32 |
+
|
33 |
== Installation ==
|
34 |
|
35 |
+
= Automatic installation =
|
36 |
+
|
37 |
+
Automatic installation is the easiest option as WordPress handles the file transfers itself and you don’t need to leave your web browser. To do an automatic install of Category Posts Widget,
|
38 |
+
|
39 |
+
1. log in to your WordPress dashboard, navigate to the Plugins menu and click Add New.
|
40 |
+
2. In the search field type “Category Posts Widget” and click Search Plugins.
|
41 |
+
3. Once you’ve found plugin, you can install it by simply clicking “Install Now”.
|
42 |
+
4. Then, go to plugins page of WordPress admin activate the plugin.
|
43 |
+
5. Now, goto the Widgets page of the Appearance section and configure the Category Posts widget.
|
44 |
+
|
45 |
+
= Manual installation =
|
46 |
+
|
47 |
1. Download the plugin.
|
48 |
2. Upload it to the plugins folder of your blog.
|
49 |
+
3. Activate the plugin through the 'Plugins' menu in WordPress
|
50 |
+
4. Now, goto the Widgets page of the Appearance section and configure the Category Posts widget.
|
51 |
|
52 |
== Upgrade Notice ==
|
53 |
|
54 |
+
* Please consider to re-configure the widget as the latest version has numerous changes from previous.
|
55 |
+
* Version 4.0 uses CSS file for styling the widget in front end.
|
56 |
+
* Version 3.0 or later version uses WordPress 2.9's built in post thumbnail functionality.
|
57 |
+
|
58 |
|
59 |
== Screenshots ==
|
60 |
|
61 |
1. The widget configuration dialog.
|
62 |
+
2. Front end of the widget using a default WordPress Theme.
|
63 |
|
64 |
== Changelog ==
|
65 |
|
66 |
+
4.0
|
67 |
+
|
68 |
+
* Added CSS file for post styling
|
69 |
+
* Now compaitable with latest versions of WordPress
|
70 |
+
|
71 |
3.3
|
72 |
|
73 |
* Fixed random sort bug.
|
screenshot-1.png
CHANGED
Binary file
|