<?php
/*
Plugin Name: count_posts
Plugin URI: http://wordpress.org/support/10/10321
Description: A simple function to count posts, with the option of filtering by category or over a recent time span (in days).
Version: 1.0
Author: Clint Howarth
Author URI:
*/

function count_posts ($category '',
$span '0')
{
global 
$tableposts$tablecategories$tablepost2cat$wpdb;
$now current_time('mysql');

// want the date of $span days ago
if ($span != 0) {
$then gmdate('Y-m-d H:i:s',
(
time() + (get_settings('gmt_offset') * 3600) -
(
$span 86400))
);
}

// get category id based on name
if (!empty($category)) {
$catid $wpdb->get_var("SELECT cat_id FROM $tablecategories
WHERE cat_name = '$category' "
);
}

// start the query
$query "SELECT COUNT(*) FROM $tableposts ";

if (!empty(
$category)) {
$query .= "LEFT JOIN $tablepost2cat ON
($tableposts.ID = $tablepost2cat.post_id) "
;
}

$query .= "WHERE (post_date <= '$now') ";

if (!empty(
$category)) {
$query .= "AND (category_id = $catid) ";
}

if (
$span != 0) {
$query .= "AND (post_date >= '$then') ";
}

$query .= "AND (post_status = 'publish') ";

$number $wpdb->get_var($query);

echo 
$number;

}
?>