Here is sample code I use to count words in a post ( I found it somewhere while searching something else). Put the code in functions.php (no need to write plugin)
function blog_post_wordcount() { global $page, $pages; if ( !function_exists('str_word_count') ) { return str_word_count(strip_tags($pages[$page-1])); } else { return count(explode(" ",strip_tags($pages[$page-1]))); } }
You can call blog_post_wordcount() from template. Following code will display ad only if a post has more than 100 words:
$words=blog_post_wordcount(); if ( $words >= 100 ) { show_ad(): }
nice, I have a summary of articles on my main page and this will help readers decide if they have time to read the whole thing.
Thank you for this information. :)
I am looking for a php or java script which allow message to be written back above the message box together with the message date on the left? Can you help? urgently
What I did not understand is
if ( !function_exists(‘str_word_count’) ) {
return str_word_count(strip_tags($pages[$page-1]));
}
If function does not exist, use it?