Version Description
Download this release
Release Info
Developer | ZephyrWest |
Plugin | Category Posts Widget |
Version | 1.2 |
Comparing to | |
See all releases |
Code changes from version 1.1 to 1.2
- cat-posts.php +17 -9
- readme.txt +31 -30
cat-posts.php
CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Category Posts Widget
|
|
4 |
Plugin URI: http://jameslao.com/
|
5 |
Description: Adds a widget that can display a specified number of posts from a single category. Can also set how many widgets to show.
|
6 |
Author: James Lao
|
7 |
-
Version: 1.
|
8 |
Author URI: http://jameslao.com/
|
9 |
*/
|
10 |
|
@@ -12,14 +12,22 @@ Author URI: http://jameslao.com/
|
|
12 |
function nk_cat_posts_widget($args, $number = 1) {
|
13 |
extract($args);
|
14 |
$options = get_option('widget_cat_posts');
|
15 |
-
$
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
$num = $options[$number]['num'] > 15 ? 15 : $options[$number]['num'];
|
18 |
|
19 |
echo $before_widget;
|
20 |
echo $before_title . $title . $after_title;
|
21 |
echo '<ul>';
|
22 |
-
nk_cat_posts($
|
23 |
echo '</ul>';
|
24 |
echo $after_widget;
|
25 |
}
|
@@ -27,7 +35,7 @@ function nk_cat_posts_widget($args, $number = 1) {
|
|
27 |
// The control dialog.
|
28 |
function nk_cat_posts_widget_control($number) {
|
29 |
$options = $newoptions = get_option('widget_cat_posts');
|
30 |
-
if ( $_POST["cat-posts-title-" . $number] ) {
|
31 |
$newoptions[$number]['title'] = strip_tags(stripslashes($_POST["cat-posts-title-" . $number]));
|
32 |
$newoptions[$number]['cat'] = $_POST["show-cat-id-" . $number];
|
33 |
$newoptions[$number]['num'] = is_numeric($_POST["cat-posts-num-" . $number]) && $_POST["cat-posts-num-" . $number]!=0 ? $_POST["cat-posts-num-" . $number] : 5;
|
@@ -53,7 +61,7 @@ function nk_cat_posts_widget_page() {
|
|
53 |
<h2>Category Posts Widgets</h2>
|
54 |
<p style="line-height: 30px;">How many category posts widgets would you like?
|
55 |
<select id="cat-posts-number" name="cat-posts-number" value="<?php echo $options['num_of_widgets']; ?>">
|
56 |
-
<?php for ( $i = 1; $i
|
57 |
</select>
|
58 |
<span class="submit"><input type="submit" name="cat-posts-number-submit" id="cat-posts-number-submit" value="<?php echo attribute_escape(__('Save')); ?>" /></span></p>
|
59 |
</form>
|
@@ -66,7 +74,7 @@ function nk_cat_posts_widget_setup() {
|
|
66 |
$options = $newoptions = get_option('widget_cat_posts');
|
67 |
if ( isset($_POST['cat-posts-number-submit']) ) {
|
68 |
$number = (int) $_POST['cat-posts-number'];
|
69 |
-
if ( $number >
|
70 |
if ( $number < 1 ) $number = 1;
|
71 |
$newoptions['num_of_widgets'] = $number;
|
72 |
}
|
@@ -82,10 +90,10 @@ function nk_cat_posts_widget_register() {
|
|
82 |
$options = get_option('widget_cat_posts');
|
83 |
$num_of_widgets = $options['num_of_widgets'];
|
84 |
if ( $num_of_widgets < 1 ) $num_of_widgets = 1;
|
85 |
-
if ( $num_of_widgets >
|
86 |
$dims = array('width' => 300, 'height' => 150);
|
87 |
$class = array('classname' => 'widget_cat_posts');
|
88 |
-
for ($i = 1; $i <=
|
89 |
$name = sprintf('Category Posts %d', $i);
|
90 |
$id = "cat-posts-$i";
|
91 |
wp_register_sidebar_widget($id, $name, $i <= $num_of_widgets ? 'nk_cat_posts_widget' : '', $class, $i);
|
4 |
Plugin URI: http://jameslao.com/
|
5 |
Description: Adds a widget that can display a specified number of posts from a single category. Can also set how many widgets to show.
|
6 |
Author: James Lao
|
7 |
+
Version: 1.2
|
8 |
Author URI: http://jameslao.com/
|
9 |
*/
|
10 |
|
12 |
function nk_cat_posts_widget($args, $number = 1) {
|
13 |
extract($args);
|
14 |
$options = get_option('widget_cat_posts');
|
15 |
+
$catID = empty($options[$number]['cat']) ? 1 : $options[$number]['cat'];
|
16 |
+
|
17 |
+
// If not title, use the name of the category.
|
18 |
+
if( empty($options[$number]['title']) ) {
|
19 |
+
$categoryInfo = get_category($catID);
|
20 |
+
$title = $categoryInfo->name;
|
21 |
+
} else {
|
22 |
+
$title = $options[$number]['title'];
|
23 |
+
}
|
24 |
+
|
25 |
$num = $options[$number]['num'] > 15 ? 15 : $options[$number]['num'];
|
26 |
|
27 |
echo $before_widget;
|
28 |
echo $before_title . $title . $after_title;
|
29 |
echo '<ul>';
|
30 |
+
nk_cat_posts($catID, $num);
|
31 |
echo '</ul>';
|
32 |
echo $after_widget;
|
33 |
}
|
35 |
// The control dialog.
|
36 |
function nk_cat_posts_widget_control($number) {
|
37 |
$options = $newoptions = get_option('widget_cat_posts');
|
38 |
+
if ( $_POST["cat-posts-title-" . $number] || $_POST["show-cat-id-" . $number] || $_POST["cat-posts-num-" . $number] ) {
|
39 |
$newoptions[$number]['title'] = strip_tags(stripslashes($_POST["cat-posts-title-" . $number]));
|
40 |
$newoptions[$number]['cat'] = $_POST["show-cat-id-" . $number];
|
41 |
$newoptions[$number]['num'] = is_numeric($_POST["cat-posts-num-" . $number]) && $_POST["cat-posts-num-" . $number]!=0 ? $_POST["cat-posts-num-" . $number] : 5;
|
61 |
<h2>Category Posts Widgets</h2>
|
62 |
<p style="line-height: 30px;">How many category posts widgets would you like?
|
63 |
<select id="cat-posts-number" name="cat-posts-number" value="<?php echo $options['num_of_widgets']; ?>">
|
64 |
+
<?php for ( $i = 1; $i <= 20; ++$i ) echo "<option value='$i' ".($options['num_of_widgets']==$i ? "selected='selected'" : '').">$i</option>"; ?>
|
65 |
</select>
|
66 |
<span class="submit"><input type="submit" name="cat-posts-number-submit" id="cat-posts-number-submit" value="<?php echo attribute_escape(__('Save')); ?>" /></span></p>
|
67 |
</form>
|
74 |
$options = $newoptions = get_option('widget_cat_posts');
|
75 |
if ( isset($_POST['cat-posts-number-submit']) ) {
|
76 |
$number = (int) $_POST['cat-posts-number'];
|
77 |
+
if ( $number > 20 ) $number = 20;
|
78 |
if ( $number < 1 ) $number = 1;
|
79 |
$newoptions['num_of_widgets'] = $number;
|
80 |
}
|
90 |
$options = get_option('widget_cat_posts');
|
91 |
$num_of_widgets = $options['num_of_widgets'];
|
92 |
if ( $num_of_widgets < 1 ) $num_of_widgets = 1;
|
93 |
+
if ( $num_of_widgets > 20 ) $num_of_widgets = 20;
|
94 |
$dims = array('width' => 300, 'height' => 150);
|
95 |
$class = array('classname' => 'widget_cat_posts');
|
96 |
+
for ($i = 1; $i <= 20; $i++) {
|
97 |
$name = sprintf('Category Posts %d', $i);
|
98 |
$id = "cat-posts-$i";
|
99 |
wp_register_sidebar_widget($id, $name, $i <= $num_of_widgets ? 'nk_cat_posts_widget' : '', $class, $i);
|
readme.txt
CHANGED
@@ -1,30 +1,31 @@
|
|
1 |
-
=== Plugin Name ===
|
2 |
-
Contributors: James Lao
|
3 |
-
Donate link: http://jameslao.com/
|
4 |
-
Tags: category, posts, widget
|
5 |
-
Requires at least: 2.2
|
6 |
-
Tested up to: 2.3
|
7 |
-
Stable tag: 1.
|
8 |
-
|
9 |
-
Adds a widget that shows the most recent posts in a single category. You can specify how many posts to show and from which category as well as how many widgets to show.
|
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 |
-
|
16 |
-
|
17 |
-
*
|
18 |
-
*
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
1 |
+
=== Plugin Name ===
|
2 |
+
Contributors: James Lao
|
3 |
+
Donate link: http://jameslao.com/
|
4 |
+
Tags: category, posts, widget
|
5 |
+
Requires at least: 2.2
|
6 |
+
Tested up to: 2.3
|
7 |
+
Stable tag: 1.2
|
8 |
+
|
9 |
+
Adds a widget that shows the most recent posts in a single category. You can specify how many posts to show and from which category as well as how many widgets to show.
|
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 |
+
* Specify how many posts to show
|
18 |
+
* Set which category the posts should come form
|
19 |
+
* Designate how many of the widgets you need
|
20 |
+
|
21 |
+
== Installation ==
|
22 |
+
|
23 |
+
1. Download the plugin.
|
24 |
+
2. Upload it to the plugins folder of your blog.
|
25 |
+
3. Goto the Plugins section of the WordPress admin and activate the plugin.
|
26 |
+
4. Goto the Widget tab of the Presentation section and configure the widget.
|
27 |
+
|
28 |
+
== Screenshots ==
|
29 |
+
|
30 |
+
1. A look at the configuration dialog for a Category Posts widget.
|
31 |
+
2. You can set how many widgets you want.
|