This repository has been archived by the owner on Jan 19, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from andrewhayward/master
Updates
- Loading branch information
Showing
7 changed files
with
235 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
=== Recent Category Posts Widget === | ||
Contributors: georgestephanis | ||
Donate link: http://www.charitywater.org/donate/ | ||
Tags: category, categories, widget | ||
Requires at least: 2.7 | ||
Tested up to: 3.4.1 | ||
Stable tag: 2.0 | ||
|
||
This widget will let you display a list of the most recent posts in a single category in your sidebar. | ||
|
||
== Description == | ||
|
||
Sure, WordPress has a widget for displaying your most recent posts, but what if you want to only display the posts from a single category in a widget, and not everything? This plugin Widget lets you set the title, category, and quantity of posts to display, then it kicks out a list of the most recent posts in that category. | ||
|
||
== Installation == | ||
|
||
1. Upload the file `widget_cat_posts.php` to the `/wp-content/plugins/` directory | ||
1. Activate the plugin through the 'Plugins' menu in WordPress | ||
1. Position the widget in the desired sidebar through the `widgets` admin page | ||
1. Set the category and number of posts to display | ||
|
||
== Frequently Asked Questions == | ||
|
||
= WordPress doesn't let you do this? Really? = | ||
|
||
Nope. Really. | ||
|
||
== Changelog == | ||
|
||
= 2.0 = | ||
* Now Multi-Widget Friendly, with 200% more awesome! | ||
|
||
= 1.0 = | ||
* Release. | ||
|
||
== Upgrade Notice == | ||
|
||
= 2.0 = | ||
When you upgrade, you will need to re-create your widget from version 1.0 -- there is no clean upgrade path. | ||
|
||
= 1.0 = | ||
Not Applicable. Initial Release. | ||
|
93 changes: 93 additions & 0 deletions
93
wp-content/plugins/category-posts-widget/widget_cat_posts.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
/* | ||
Plugin Name: Recent Category Posts Widget | ||
Plugin URI: http://www.Stephanis.info/ | ||
Description: Displays the most recent posts in the selected category in a simple list. | ||
Author: E. George Stephanis | ||
Author URI: http://www.Stephanis.info/ | ||
Version: 2.0 | ||
*/ | ||
|
||
class single_category_posts_widget extends WP_Widget { | ||
|
||
public function __construct() { | ||
parent::__construct( | ||
'single_category_posts_widget', | ||
'Single Category Posts Widget', | ||
array( 'description' => __( 'A widget to display the most recent posts from a single category' ) ) | ||
); | ||
} | ||
|
||
public function form( $instance ) { | ||
$title = isset( $instance[ 'title' ] ) ? $instance[ 'title' ] : __( 'Recent Posts in Category' ); | ||
$cat = isset( $instance[ 'cat' ] ) ? intval( $instance[ 'cat' ] ) : 0; | ||
$qty = isset( $instance[ 'qty' ] ) ? intval( $instance[ 'qty' ] ) : 5; | ||
?> | ||
<p> | ||
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> | ||
<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( $title ); ?>" /> | ||
</p> | ||
<p> | ||
<label for="<?php echo $this->get_field_id( 'cat' ); ?>"><?php _e( 'Category:' ); ?></label> | ||
<?php wp_dropdown_categories( Array( | ||
'orderby' => 'ID', | ||
'order' => 'ASC', | ||
'show_count' => 1, | ||
'hide_empty' => 0, | ||
'hide_if_empty' => false, | ||
'echo' => 1, | ||
'selected' => $cat, | ||
'hierarchical' => 1, | ||
'name' => $this->get_field_name( 'cat' ), | ||
'id' => $this->get_field_id( 'cat' ), | ||
'class' => 'widefat', | ||
'taxonomy' => 'category', | ||
) ); ?> | ||
</p> | ||
<p> | ||
<label for="<?php echo $this->get_field_id( 'qty' ); ?>"><?php _e( 'Quantity:' ); ?></label> | ||
<input id="<?php echo $this->get_field_id( 'qty' ); ?>" name="<?php echo $this->get_field_name( 'qty' ); ?>" type="number" min="1" step="1" value="<?php echo $qty; ?>" /> | ||
</p> | ||
<?php | ||
} | ||
|
||
public function update( $new_instance, $old_instance ) { | ||
$instance = array(); | ||
$instance['title'] = strip_tags( $new_instance['title'] ); | ||
$instance['cat'] = intval( $new_instance['cat'] ); | ||
$instance['qty'] = intval( $new_instance['qty'] ); | ||
return $instance; | ||
} | ||
|
||
public function widget( $args, $instance ) { | ||
extract( $args ); | ||
$title = apply_filters( 'widget_title', $instance['title'] ); | ||
$cat = $instance['cat']; | ||
$qty = (int) $instance['qty']; | ||
|
||
echo $before_widget; | ||
if ( ! empty( $title ) ) echo $before_title . $title . $after_title; | ||
echo self::get_cat_posts( $cat, $qty ); | ||
echo $after_widget; | ||
} | ||
|
||
public function get_cat_posts( $cat, $qty ) { | ||
$posts = get_posts( Array( | ||
'category' => $cat, | ||
'orderby' => 'date', | ||
'order' => 'DESC', | ||
'numberposts' => $qty | ||
)); | ||
|
||
$returnThis = ''; | ||
if( count( $posts ) ) | ||
$returnThis .= '<ul class="'.__CLASS__.'">'."\r\n"; | ||
foreach( $posts as $post ) | ||
$returnThis .= "\t".'<li><a href="'.get_permalink( $post->ID ).'">'.$post->post_title.'</a></li>'."\r\n"; | ||
if( count( $posts ) ) | ||
$returnThis .= '</ul>'."\r\n"; | ||
return $returnThis; | ||
} | ||
|
||
} | ||
add_action( 'widgets_init', create_function( '', 'register_widget( "single_category_posts_widget" );' ) ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.