Guest User

Untitled

a guest
Dec 18th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. <table cellspacing="10">
  2. <tr>
  3. <th width="50"></th>
  4. <th>Posts</th>
  5. <th>Avg. Words</th>
  6. <th>Total Words</th>
  7. <th>Avg. Comments</th>
  8. <th>Total Comments</th>
  9. </tr>
  10. <?php
  11. $distinct_years = $wpdb->get_col( "SELECT DISTINCT YEAR(post_date) FROM $wpdb->posts WHERE YEAR(post_date) != 0 ORDER BY YEAR(post_date) ASC" );
  12.  
  13. foreach( $distinct_years as $year ) {
  14. $total_posts = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE YEAR(post_date) = '$year' AND post_status = 'publish'" );
  15.  
  16. $total_words = 0;
  17. $all_content = $wpdb->get_col( "SELECT post_content FROM $wpdb->posts WHERE YEAR(post_date) = '$year' AND post_status = 'publish'" );
  18. foreach ( $all_content as $c ) {
  19. $c = strip_tags( $c );
  20. $c = preg_replace( "/\s+/", ' ', $c );
  21. $words = explode( ' ', $c );
  22. $total_words += count( $words );
  23. }
  24.  
  25. $avg_words = floor( $total_words / $total_posts );
  26.  
  27. $total_comments = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments WHERE YEAR(comment_date) = '$year' AND comment_approved = '1'" );
  28. $avg_comments = floor( $total_comments / $total_posts );
  29.  
  30. $total_posts = number_format( $total_posts );
  31. $avg_words = number_format( $avg_words );
  32. $total_words = number_format( $total_words );
  33. $avg_comments = number_format( $avg_comments );
  34. $total_comments = number_format( $total_comments );
  35.  
  36.  
  37. 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>";
  38. }
  39.  
  40. ?>
  41. </table>
Add Comment
Please, Sign In to add comment