Created
January 3, 2012 04:28
-
-
Save alexkingorg/1553482 to your computer and use it in GitHub Desktop.
WordPress per-year blog stats
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
<?php | |
header('Content-type: text/plain'); | |
global $wpdb; | |
?> | |
<table class="numbers"> | |
<thead> | |
<tr> | |
<th> </th> | |
<th>Posts</th> | |
<th>Avg. Length</th> | |
<th>Total Length</th> | |
<th>Comments (Mine)</th> | |
</tr> | |
</thead> | |
<tbody> | |
<?php | |
for ($i = intval(date('Y')); $i >= 2002; $i--) { | |
$from = $i; | |
$to = $i + 1; | |
$posts_count = $wpdb->get_var(" | |
SELECT COUNT(*) | |
FROM `wp_posts` | |
WHERE post_date >= '$from-01-01' | |
AND post_date < '$to-01-01' | |
AND post_status = 'publish'; | |
"); | |
$posts_length_avg = $wpdb->get_var(" | |
SELECT AVG(LENGTH(post_content)) | |
FROM `wp_posts` | |
WHERE post_date >= '$from-01-01' | |
AND post_date < '$to-01-01' | |
AND post_status = 'publish'; | |
"); | |
$posts_length_total = $wpdb->get_var(" | |
SELECT SUM(LENGTH(post_content)) | |
FROM `wp_posts` | |
WHERE post_date >= '$from-01-01' | |
AND post_date < '$to-01-01' | |
AND post_status = 'publish'; | |
"); | |
$comments_total = $wpdb->get_var(" | |
SELECT COUNT(*) | |
FROM `wp_comments` | |
WHERE comment_date >= '$from-01-01' | |
AND comment_date < '$to-01-01' | |
AND comment_approved = '1'; | |
"); | |
$comments_mine = $wpdb->get_var(" | |
SELECT COUNT(*) | |
FROM `wp_comments` | |
WHERE comment_date >= '$from-01-01' | |
AND comment_date < '$to-01-01' | |
AND comment_approved = '1' | |
AND user_ID = 1; | |
"); | |
?> | |
<tr> | |
<td><?php echo $i; ?></td> | |
<td><?php echo number_format($posts_count, 0); ?></td> | |
<td><?php echo number_format($posts_length_avg, 0); ?></td> | |
<td><?php echo number_format($posts_length_total, 0); ?></td> | |
<td><?php echo number_format($comments_total, 0); ?> (<?php echo number_format($comments_mine, 0); ?>)</td> | |
</tr> | |
<?php | |
} | |
?> | |
</tbody> | |
</table> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment