Display word count for stories
pgrote - October 18, 2005 - 00:00
Hello,
Is there an exiting option to display the number of words in a story? I looked at the options and couldn't find it.
I'd settle for it showing under RECENT POSTS, in the Read Comments line after story, etc. Just somewhere it is displayed.
Thanks!

You can do this in the
You can do this in the theme.
In a PHPTemplate theme, put the following code in node.tpl.php where you want the word count to display:
<?php$wordcount = count(explode(" ", strip_tags(trim($node->body))));
print $wordcount;
?>
If you just want this to display in stories, copy the exising node.tpl.php file to node-story.tpl.php, and insert the above code.
Thanks! I will give that
Thanks! I will give that shot!
Ok, I did that.
Ok, I did that.
It didn't turn out right. lol
Couple of issues:
1) On the front page the word count shows as 1 no matter what.
2) I can't figure out where to put it so that it goes after this:
» add new comment | 7 reads | unsubscribe post
Any ideas?
Thanks again!
Here's one way
By this time, you might have figured it out already, but just in case:
In
node.tpl.php, add this line:<?php $wordcount = " | ".count(explode(" ", strip_tags(trim($content))))." words" ; ?>I added it on a new line just after line 4, which has
"}?>"in my version of the file. Then, make the following changes to the line that starts with"<?php if ($links)"<?php if ($links) { ?> <div class="links">» <?php print $links; print $wordcount ?><?php }; ?>And that should take care of both issues. One caveat -- if you have any modules activated that add stuff to the $content block (e.g. the nodevote module), it will throw off the count.