Viewing word count for topics in phpBB3

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.

1 Response to “Viewing word count for topics in phpBB3”


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

    Hello!

    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.

    Thanks!


Leave a Reply




Blog Stats

  • 5,003 hits

My Work Blog

This is my code blog, where I post any interesting code I develop during the course of my work. My research blog is on Blogger, and that is where I update the course of my research work at Columbia University. Blogger's source code formatting is not up to par, but Wordpress' is excellent, which is why my code is being posted on this blog.