Adding a FanUpdate Entry Word Count

This is a rough 30-second guide, code is short & sweet, and I’ve not run the mod past Jenny… but, I’m not one to refuse a request when it’s simple to implement.

In your fanupdate folder (or the root of your website if that’s where you’ve got it installed), open the class folder, and find FanUpdate_Post.php.

Right near the very bottom of the file, look for:
$text = str_replace('{{body}}', $this->getBodyFormatted(), $text);

On a new line right after that one, add:
$text = str_replace('{{word_count}}', str_word_count($this->getBody()), $text);

Now, in your blog control panel, go to Options -> Templates, and in the entry_template: box put {{word_count}} where you’d like the word count to appear. E.g. on a default install, I edited the following line:
<p class="catfile">Posted {{date}}. Filed under {{category}}. {{comment_link}}. Word Count: {{word_count}}</p>

Save your settings and refresh your blog, it should appear exactly where you placed it.

6 comments so far

  1. Julia said:
    On 17 Nov at 8:24 pm

    I don’t get the point of word count in blog entries. It’s doesn’t even look “cool”.

  2. Jem said:
    On 17 Nov at 8:31 pm

    Don’t ask me, I’m just doing as I’m told ;)

  3. Kim said:
    On 17 Nov at 8:35 pm

    Thanks for this Jem, it was very useful. :)

  4. Kim said:
    On 17 Nov at 8:37 pm

    Damn, clicked submit before I was finished. =/
    Also wanted to say:
    I tested it out and it worked… Not that I’ll probably keep it but it was useful to play with.

  5. Alexandra said:
    On 18 Nov at 1:35 am

    Thanks for that Jem, I’ll bookmark this entry for later ^_^

  6. Julia said:
    On 18 Nov at 4:31 am

    Thanks for this, I doubt I’ll ever use it. I want to try it out but my site is down :(

    It probably is 30secs.