Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <table cellspacing="10">
- <tr>
- <th width="50"></th>
- <th>Posts</th>
- <th>Avg. Words</th>
- <th>Total Words</th>
- <th>Avg. Comments</th>
- <th>Total Comments</th>
- </tr>
- <?php
- $distinct_years = $wpdb->get_col( "SELECT DISTINCT YEAR(post_date) FROM $wpdb->posts WHERE YEAR(post_date) != 0 ORDER BY YEAR(post_date) ASC" );
- foreach( $distinct_years as $year ) {
- $total_posts = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE YEAR(post_date) = '$year' AND post_status = 'publish'" );
- $total_words = 0;
- $all_content = $wpdb->get_col( "SELECT post_content FROM $wpdb->posts WHERE YEAR(post_date) = '$year' AND post_status = 'publish'" );
- foreach ( $all_content as $c ) {
- $c = strip_tags( $c );
- $c = preg_replace( "/\s+/", ' ', $c );
- $words = explode( ' ', $c );
- $total_words += count( $words );
- }
- $avg_words = floor( $total_words / $total_posts );
- $total_comments = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments WHERE YEAR(comment_date) = '$year' AND comment_approved = '1'" );
- $avg_comments = floor( $total_comments / $total_posts );
- $total_posts = number_format( $total_posts );
- $avg_words = number_format( $avg_words );
- $total_words = number_format( $total_words );
- $avg_comments = number_format( $avg_comments );
- $total_comments = number_format( $total_comments );
- echo "<tr><td>$year</td><td align='right'>$total_posts</td><td align='right'>$avg_words</td><td align='right'>$total_words</td><td align='right'>$avg_comments</td><td align='right'>$total_comments</td></tr>";
- }
- ?>
- </table>
Add Comment
Please, Sign In to add comment