arrow-left arrow-right brightness-2 chevron-left chevron-right facebook-box facebook loader magnify menu-down rss-box star twitter-box twitter white-balance-sunny window-close
Movable Type total word count
1 min read

Movable Type total word count

Every so often curiosity gets the better of me and I want to find out (and publish) the total number of words I’ve put into the posts on this site (you can now see this at the top of my main archives page). Unfortunately, and quite surprisingly, each time I’ve looked for this functionality I’ve come up empty (and yes, I’m aware of MTWordStats, but it’s broken, at least for me); Movable Type still doesn’t count the words of individual entries for you, much less give you a function that returns a weblog-wide total.

I came up with a quick and very simple solution.

The first thing you’ll need to do is download and install the WordCount plugin, which returns the number of words in a given post. To get the total number of words throughout your weblog, you’ll need to run this plugin over all of your entries. To do that, insert the following code at the top of the template you’re going to use to display the total.

<MTEntries lastn=10000>
<?php $tWords = $tWords + <$MTWordCount$>; ?>

To display this total, place the following code in the template where you want the number shown (make sure that this code appears somewhere below the above code).

<?php echo number_format($tWords) ?>

Yep, that’s it.

You've successfully subscribed to P O L Y M A T H.
Success! Your account is fully activated, you now have access to all content.