Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
Merge pull request #52 from andrewhayward/master
Browse files Browse the repository at this point in the history
Updates
  • Loading branch information
andrewhayward committed Oct 22, 2013
2 parents c2889a4 + 446a811 commit 28de328
Show file tree
Hide file tree
Showing 7 changed files with 235 additions and 42 deletions.
43 changes: 43 additions & 0 deletions wp-content/plugins/category-posts-widget/readme.txt
@@ -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 wp-content/plugins/category-posts-widget/widget_cat_posts.php
@@ -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" );' ) );
4 changes: 2 additions & 2 deletions wp-content/themes/mozfest2012/functions.php
Expand Up @@ -34,7 +34,7 @@ function mf2012_alter_taxonomy_archive_posts ($query) {
}
}

add_filter('pre_get_posts', 'mf2012_alter_taxonomy_archive_posts');
// add_filter('pre_get_posts', 'mf2012_alter_taxonomy_archive_posts');

function mf2012_alter_posts_results ($posts) {
if (!is_array($posts)) {
Expand All @@ -43,7 +43,7 @@ function mf2012_alter_posts_results ($posts) {
return $posts;
}

add_filter('posts_results', 'mf2012_alter_posts_results');
// add_filter('posts_results', 'mf2012_alter_posts_results');

function mf2012_fix_sql ($sql) {
if (defined('TAXONOMY_ARCHIVE')) {
Expand Down
3 changes: 2 additions & 1 deletion wp-content/themes/mozfest2012/media/css/_sidebar.less
@@ -1,7 +1,8 @@
#sidebar {
float: right;
width: 300px;
margin-right: -320px;
padding: 0 5px;
margin-right: -325px;
overflow: hidden;
}

Expand Down
46 changes: 38 additions & 8 deletions wp-content/themes/mozfest2012/media/css/core.css
Expand Up @@ -25,7 +25,7 @@ body {
margin: 0;
padding: 0;
font-family: 'Open Sans', sans-serif;
font-size: 13px;
font-size: 14px;
color: #4d4d4d;
}
.constrained {
Expand Down Expand Up @@ -94,6 +94,7 @@ a {
body.archive article {
margin-top: 50px;
}
/* revert the big top margin for tag archives */
body.tag article {
margin-top: 0;
}
Expand Down Expand Up @@ -128,35 +129,48 @@ img.alignleft {
float: left;
margin: 0 1em 0 0;
}
img.aligncenter {
margin: 0 auto;
display: block;
}
img.alignright {
float: right;
margin: 0 0 0 1em;
}
body.blog #content-inner .blog-title,
body.tag #content-inner .blog-title {
body.blog .blog-title,
body.tag .blog-title {
margin-bottom: 1em;
padding-top: 1em;
border-top: 1px solid #E5E5E6;
border-top: solid 1px #E5E5E6;
}
body.blog #content-inner article:first-child .blog-title,
body.tag #content-inner h2 + article .blog-title {
border-top: none;
margin-top: 0;
padding-top: 0;
}
body.blog #content-inner object,
body.single-post #content-inner object,
body.tag #content-inner object,
body.blog #content-inner img,
body.single-post #content-inner img,
body.tag #content-inner img {
width: 100%;
max-width: 100%;
height: auto;
margin-bottom: 1em;
display: block;
}
body.blog #content-inner img.alignnone,
body.single-post #content-inner img.alignnone,
body.tag #content-inner img.alignnone,
body.blog #content-inner img.alignleft,
body.blog #content-inner img.alignright,
body.single-post #content-inner img.alignleft,
body.single-post #content-inner img.alignright,
body.tag #content-inner img.alignleft,
body.blog #content-inner img.aligncenter,
body.single-post #content-inner img.aligncenter,
body.tag #content-inner img.aligncenter,
body.blog #content-inner img.alignright,
body.single-post #content-inner img.alignright,
body.tag #content-inner img.alignright {
width: auto;
display: inline-block;
Expand All @@ -166,6 +180,21 @@ body.single-post #content-inner img.alignleft,
body.tag #content-inner img.alignleft {
margin-right: 10px;
}
body.blog #content-inner img.aligncenter,
body.single-post #content-inner img.aligncenter,
body.tag #content-inner img.aligncenter {
display: block;
}
body.blog #content-inner img.alignright,
body.single-post #content-inner img.alignright,
body.tag #content-inner img.alignright {
margin-left: 10px;
}
body.blog #content-inner img.alignleft,
body.single-post #content-inner img.alignleft,
body.tag #content-inner img.alignleft {
margin-right: 10px;
}
body.blog #content-inner img.alignright,
body.single-post #content-inner img.alignright,
body.tag #content-inner img.alignright {
Expand Down Expand Up @@ -571,7 +600,8 @@ pre.template {
#sidebar {
float: right;
width: 300px;
margin-right: -320px;
padding: 0 5px;
margin-right: -325px;
overflow: hidden;
}
#sidebar > .primary {
Expand Down
56 changes: 39 additions & 17 deletions wp-content/themes/mozfest2012/media/css/core.less
Expand Up @@ -8,7 +8,7 @@ body {
margin: 0;
padding: 0;
font-family: 'Open Sans', sans-serif;
font-size: 13px;
font-size: 14px;
color: @slate;
}

Expand Down Expand Up @@ -129,6 +129,11 @@ img.alignleft {
margin: 0 1em 0 0;
}

img.aligncenter {
margin: 0 auto;
display: block;
}

img.alignright {
float: right;
margin: 0 0 0 1em;
Expand All @@ -148,23 +153,40 @@ body.tag #content-inner h2 + article .blog-title {
padding-top: 0;
}

body.blog #content-inner img,
body.single-post #content-inner img,
body.tag #content-inner img {
width: 100%;
height: auto;
margin-bottom: 1em;
display: block;
}
body.blog,
body.single-post,
body.tag {
#content-inner {
object,
img {
max-width: 100%;
height: auto;
margin-bottom: 1em;
display: block;
}

body.blog #content-inner img.alignleft,
body.blog #content-inner img.alignright,
body.single-post #content-inner img.alignleft,
body.single-post #content-inner img.alignright,
body.tag #content-inner img.alignleft,
body.tag #content-inner img.alignright {
width: auto;
display: inline-block;
img {
&.alignnone,
&.alignleft,
&.aligncenter,
&.alignright {
width: auto;
display: inline-block;
}

&.alignleft {
margin-right: 10px;
}

&.aligncenter {
display: block;
}

&.alignright {
margin-left: 10px;
}
}
}
}

body.blog #content-inner img.alignleft,
Expand Down

0 comments on commit 28de328

Please sign in to comment.