Viewing word count for topics in phpBB3

2 Jul

Question: you want to be able to see the word count for each post in phpBB3. How do you do that?

Answer: You need to edit two files in the phpBB3 code to get this to work. Read on.

We need to set up a variable called MESSAGE_ROW_COUNT, and display that in the template.

First of all, open /<phpbb3>/viewtopic.php and go to near line 1401. This is where the $postrow array is created.

      $postrow = array(
         // more code setting up $postrow elements

Somewhere in the middle, add this additional element:

                'MESSAGE_WORD_COUNT'                    => str_word_count($message),

Then go to /styles/prosilver/template/ and go to line 189, and add this line:

     <!-- IF postrow.POSTER_POSTS != '' --><dd><strong>Word Count:</strong> {postrow.MESSAGE_WORD_COUNT}</dd><!-- ENDIF -->

I put this in line 189, where it is just below the name and details of the person who posted the article. However, you may prefer to put it somewhere else.


2 Responses to “Viewing word count for topics in phpBB3”

  1. Sarah August 9, 2009 at 11:15 am #


    Firstly, I’d like to say thanks for this little hack explanation, it’s worked wonders.

    Just curiously, are you aware of any way to perhaps modify the array entry so that the word count excludes any BB code? for instance, it’s registering a particular word count in a post on my forum as 40-odd words whereas the sentence is only just 20, and is considering the BB code to be a significant amount of the words.


  2. sumanrs May 21, 2010 at 1:55 am #

    Hi Sarah,

    First of all, sorry for the really late (months-late) reply! I haven’t been on this blog for a while …

    Regarding excluding the BB code – hmmm, I’m not sure, that would be useful. I’m thinking that there must be some code out there that can strip out the BB code (kinda like PHP’s strip_tags() function to remove HTML tags) but I don’t know of any offhand.

    If I find anything I’ll post a link.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: