Support » Plugins » Word Count

  • Open b2templates.funtions.php and find this in your POST TAGS section, it’s around line 599 depending on the hacks you already have in there:

    function get_the_content($more_link_text='(more...)', $stripteaser=0, $more_file='') {
    global $id,$postdata,$more,$c,$withcomments,$page,$pages,$multipage,$numpages;
    global $HTTP_SERVER_VARS, $preview;
    global $querystring_start, $querystring_equal, $querystring_separator;
    $output = '';
    if ($more_file != '') {
    } else {
    $content=explode('<!--more-->', $content);
    if ((preg_match('/<!--noteaser-->/', $postdata['Content']) && ((!$multipage) || ($page==1))))
    if (($more) && ($stripteaser))
    $output .= $teaser;
    if (count($content)>1) {
    if ($more) {
    $output .= ''.$content[1];
    } else {
    $output .= '<span id="varP'.$id.'">
    read more »</span><div id="varXYZ'.$id.'" style="display: none">'.$content[1].'
    « hide more</div>';
    if ($preview) { // preview fix for javascript bug with foreign languages
    $output = preg_replace('/\%u([0-9A-F]{4,4})/e', "'&#'.base_convert('\\1',16,10).';'", $output);
    And insert this right after that:
    function get_words() {
    $content = get_the_content($more_link_text,$stripteaser,$more_file);
    $content = convert_bbcode($content);
    $content = convert_gmcode($content);
    $content = convert_smilies($content);
    $content = convert_chars($content,"html");
    $stripper = "";
    $wordcount = strip_tags($content,$stripper);
    $wordcount = explode(" ",$wordcount);
    $wordcount = count($wordcount);
    echo "$wordcount words in this post";

    Call this function in your index.php with:
    <?php get_words()?>

Viewing 15 replies - 1 through 15 (of 45 total)
  • wow. much thanks 🙂 works perfectly

    Welcome! I’m using it for my NaNoWriMo blog. 🙂 Comes in handy!

    Hey SG, does this differ from the one you pointed out to me on the b2 board, or are you posting it here for the sake of convenience? 🙂

    Sorry guys, I tried to clean up the escaping in SG’s post and I may have borked it a little. If you mail me the code I’ll put it up somewhere on

    Ok, Allusion, emailing it to you. :p

    Cena, it’s the same, just making it easier when you know what line to look for!

    SG, if you can stand one more question about this: I saw your NaNoWriMo blog, where you’ve got the total number of words written so far, a neat trick that I really like. If it’s a hack, would you show us how it’s done? 🙂

    Cena, not a hack, I just go in there and change it each day. 🙂 I wish there was a total for the words, but until someone comes up with it, manual is the way! 🙂

    hello, I have put that in the template, but… it shows “word” or “letters”? In short entry, I have about 22,xxx words? owh.. i put it on

    Yeah, that code is weird… 🙂

    That code is for getting the word count for every post in your database.

    Thank you Allusion!! 🙂 Excellent!

    I second SG’s comment. 🙂



    ehy guys, just calculate how many words you wrote is boooring.. why don’t calculate something else?
    for example, obtain the total of the LETTERS (spaces included) you typed and assign it to $totaletters, then calculate..
    $calories = $totaletters*0.0819398; // one keystroke = 0.0819398 calories
    echo ‘calories wasted: ‘. number_format($calories);
    </pre> obtain how many calories you wasted with your blog 😀
    or (better!!!)
    $sexcal = $calories/250; // about 250 calories each time you have sex
    echo ‘which means i could have sex: ‘. number_format($sexcal);
    ?> times!!!
    to obtain how many times you could have sex instead of blogging for the same amount of calories 😀
    ghghghghghghghghghg a bit of fun out of this hell of world 🙂 🙂

    I would think that it would figure that out as well, Devan. Have you tested it?

Viewing 15 replies - 1 through 15 (of 45 total)
  • The topic ‘Word Count’ is closed to new replies.