Changeset 1303349
- Timestamp:
- 12/08/2015 10:53:39 PM (9 years ago)
- Location:
- post-word-count
- Files:
-
- 3 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
post-word-count/trunk/post-word-count.php
r155541 r1303349 4 4 Plugin URI: http://wordpress.org/extend/plugins/post-word-count/ 5 5 Description: Outputs the total number of words in all posts or the number of words in a single post. 6 Version: 1. 16 Version: 1. 7 7 Author: Nick Momrik 8 8 Author URI: http://nickmomrik.com/ 9 9 */ 10 10 11 function mdv_post_word_count( $single = false) {11 function mdv_post_word_count() { 12 12 global $wpdb, $id; 13 $now = gmdate( "Y-m-d H:i:s",time());13 $now = gmdate(); 14 14 15 if ($single) $query = "SELECT post_content FROM $wpdb->posts WHERE ID = '$id'"; 16 else $query = "SELECT post_content FROM $wpdb->posts WHERE post_status = 'publish' AND post_date < '$now'"; 15 if ( $single ) { 16 $query = $wpdb->prepare( "SELECT post_content FROM $wpdb->posts WHERE ID = %d", $id ); 17 } else { 18 $query = $wpdb->prepare( "SELECT post_content FROM $wpdb->posts WHERE post_status = 'publish' AND post_date < %s", $now ); 19 } 17 20 18 $words = $wpdb->get_results($query); 19 if ($words) { 20 foreach ($words as $word) { 21 $post = strip_tags($word->post_content); 22 $post = explode(' ', $post); 23 $count = count($post); 21 $words = $wpdb->get_results( $query ); 22 if ( $words ) { 23 $oldcount = 0; 24 foreach ( $words as $word ) { 25 $post = strip_tags( $word->post_content ); 26 $post = explode( ' ', $post ); 27 $count = count( $post ); 24 28 $totalcount = $count + $oldcount; 25 29 $oldcount = $totalcount; 26 30 } 27 31 } else { 28 $totalcount =0;32 $totalcount0; 29 33 } 30 echo number_format($totalcount); 34 35 echo number_format( $totalcount ); 31 36 } 32 ?> -
post-word-count/trunk/readme.txt
r1303343 r1303349 2 2 Contributors: nickmomrik 3 3 Tags: posts, count, words 4 Stable tag: 1.1 4 Stable tag: 1.2 5 Tested up to: 4.4 5 6 6 7 Counts the total number of words in all posts or the number of words in a single post. … … 14 15 The default is to count the total number of words in all posts. If you would like the number of words displayed for a particular post or page, use the following inside "the loop" 15 16 16 `<?php mdv_post_word_count( true); ?>`17 `<?php mdv_post_word_count(); ?>`
Note: See TracChangeset
for help on using the changeset viewer.