WordPress.org

Ready to get started?Download WordPress

Forums

Word Count (45 posts)

  1. Trinity22
    Member
    Posted 10 years ago #

    wow. much thanks :) works perfectly

  2. southerngal
    Member
    Posted 10 years ago #

    Welcome! I'm using it for my NaNoWriMo blog. :) Comes in handy!

  3. Cena
    Member
    Posted 10 years ago #

    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? :)

  4. Matt Mullenweg
    Troublemaker
    Posted 10 years ago #

    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 wordpress.org.

  5. southerngal
    Member
    Posted 10 years ago #

    Ok, Allusion, emailing it to you. :p

  6. southerngal
    Member
    Posted 10 years ago #

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

  7. Cena
    Member
    Posted 10 years ago #

    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? :)

  8. southerngal
    Member
    Posted 10 years ago #

    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! :)

  9. thomas
    Member
    Posted 10 years ago #

    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 http://cinila.com/

  10. Michael Heilemann
    Member
    Posted 10 years ago #

    Yeah, that code is weird... :)

  11. Matt Mullenweg
    Troublemaker
    Posted 10 years ago #

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

  12. southerngal
    Member
    Posted 10 years ago #

    Thank you Allusion!! :) Excellent!

  13. Cena
    Member
    Posted 10 years ago #

    I second SG's comment. :)

  14. gat
    Member
    Posted 10 years ago #

    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..
    <pre>
    <?php
    $calories = $totaletters*0.0819398; // one keystroke = 0.0819398 calories
    echo 'calories wasted: '. number_format($calories);
    ?>
    </pre>
    ..to obtain how many calories you wasted with your blog :D
    or (better!!!)
    <pre>
    <?php
    $sexcal = $calories/250; // about 250 calories each time you have sex
    echo 'which means i could have sex: '. number_format($sexcal);
    ?> times!!!
    </pre>
    to obtain how many times you could have sex instead of blogging for the same amount of calories :D
    ghghghghghghghghghg a bit of fun out of this hell of world :) :)

  15. southerngal
    Member
    Posted 10 years ago #

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

  16. devan
    Member
    Posted 10 years ago #

    Yeah... What I get when I use it on my main blog page is the total number of words appearing on just that page.
    So, for a 100-word post with 25 words before <!--more-->, I get a count of 25 words on my main blog page and either 75 or 100 on my single post page (depending on whether I've also used <!--noteaser-->).
    That make any sense?
    Thanks
    Devan

  17. southerngal
    Member
    Posted 10 years ago #

    Weird! Maybe something in the code can be changed to reflect that there is more to the post.

  18. devan
    Member
    Posted 10 years ago #

    I'd like to think so, too, but I beyond staring at it in b2template.functions.php I haven't a clue where to start (as I don't really know PHP)... Any suggestions?

  19. southerngal
    Member
    Posted 10 years ago #

    I have no idea! I just found the code and posted it here. I'm sure someone will post after me with the fix. ;)

  20. devan
    Member
    Posted 10 years ago #

    There's a related conversation that's picked up over here...

  21. Cena
    Member
    Posted 10 years ago #

    I'm using version 1.0-alpha-2, and I'd like to use Matt's function of just keeping track of total words in *all* posts (see above). I've tried putting it in template.functions.php, as well as functions.php, but neither displays anything when I put the function call in my index.php. (By the way, should it be <?php get_words(); ?> or without the semi-colon?)
    The good news is it doesn't crash anything, it just doesn't display. I did check the database table names that it's referring to, in case there'd been any change, but all that looks okay. Help?

  22. Cena
    Member
    Posted 10 years ago #

    *bumps because I really really want to use this function*

  23. southerngal
    Member
    Posted 10 years ago #

    I put mine in commentposts.php
    <?
    ⁄* b2stats.php
    * An addon to B2 which diplays b2 stats
    * Demo of this file @ http:⁄⁄www.orientek.net⁄kore⁄gamerz⁄b2stats.php
    * Created By Lester "GamerZ" Chan - http:⁄www.gamerz.per.sg
    * Copyright ® 2002 Lester "GamerZ" Chan. All Rights Reserved.
    *
    * B2 Created By Michel V - http:⁄⁄www.cafelog.com⁄
    *
    * You may modify this file to suit your owns needs, but please keep the copyright intact. Thanks
    * Any problems, email me @ lesterch@singnet.com.sg or post it in the B2 forums @ http:⁄⁄tidakada.com⁄board⁄
    *⁄
    ⁄⁄ Start Connect To MYSQL
    require("wp-config.php");
    include("b2-include⁄b2vars.php");
    ⁄** Get Total Number of posts
    ** Params: None
    ** Returns: number of posts
    *⁄
    function stats_get_totalposts() {
    global $tableposts;
    $sql = "SELECT COUNT(ID) FROM $tableposts";
    $result = mysql_query($sql) or die(mysql_error());
    return mysql_result($result, 0);
    }
    ⁄** Get Total Number of comments
    ** Params: None
    ** Returns: number of comments
    *⁄
    function stats_get_totalcomments() {
    global $tablecomments;
    $sql = "SELECT COUNT(DISTINCT comment_ID) FROM $tablecomments";
    $result = mysql_query($sql) or die(mysql_error());
    return mysql_result($result, 0);
    }
    $words = $wpdb->get_results("SELECT post_content FROM $tableposts");
    foreach ($words as $word) {
    $post = strip_tags($word->post_content);
    $post = explode(' ', $post);
    $count = count($post);
    $totalcount = $count + $oldcount;
    $oldcount = $totalcount;
    }
    ⁄⁄ Check $user isset
    if(!isset($user) || $user == "") {
    ⁄⁄ Output General Stats
    echo "<b>".stats_get_totalposts()."<⁄b> Posts<br>\n";
    echo "<b>".stats_get_totalcomments()."<⁄b> Comments<br><br>\n";
    echo 'Total words typed:<b>'. number_format($totalcount);
    echo "<b><⁄b><br>\n";
    }
    else {
    ⁄⁄ ------------ If $user set ------------ ⁄⁄
    ⁄⁄ SNIP... Same as previous version
    } ⁄⁄ end else user set
    ?>
    Of course this board trashed the forward slashes and backslashes, but you get the idea. Is that what you wanted?
    Just call it in: <?php include('⁄home⁄username⁄public_html⁄includes⁄commentposts.php'); ?>

  24. Cena
    Member
    Posted 10 years ago #

    SG, I appreciate the response, but here's the thing: I'm very very stupid.
    This is what I need to be told in order to implement any hack:
    It works with the CVS (1.0-alpha-2 as of this moment).
    Tell me exactly where to put it. (what file, where in that file).
    Tell me exactly how/where to use/call it.
    Here's what I'd like to have: total words in all posts (like you did for your nanowrimo blog). Right now, I'm not concerned with number of posts/comments/users/etc. I just want to keep track of how many words I've written.
    Is this what your script does? (I suppose the formatting issues didn't help anything in trying to make sense of it. Do you think I could impose on you to just email it to me? (cenaATcox-internetDOTcom)

  25. southerngal
    Member
    Posted 10 years ago #

    Mailing it to you. :) I put it in with my total comments and entries posted.

  26. Nick Momrik
    Member
    Posted 10 years ago #

    Does anyone see anything wrong with the 'words' case? It is calculating the number of total words posted, but also gives an SQL error.
    function get_stats($what) {
    global $wpdb;
    switch($what) {
    case 'words':
    global $tableposts;
    $words = $wpdb->get_results("SELECT post_content FROM $tableposts");
    foreach ($words as $word) {
    $post = strip_tags($word->post_content);
    $post = explode(' ', $post);
    $count = count($post);
    $totalcount = $count + $oldcount;
    $oldcount = $totalcount;
    }
    $request = number_format($totalcount);
    break;
    case 'posts':
    global $tableposts;
    $request = "SELECT COUNT(*) FROM $tableposts WHERE post_status = 'publish'";
    break;
    case 'comments':
    global $tablecomments;
    $request = "SELECT COUNT(*) FROM $tablecomments";
    break;
    }
    echo $wpdb->get_var($request);
    }
    I have this in the my-hacks.php file and am calling it from index.php. The hack file option is turned on in the admin.
    Thanks!

  27. Nick Momrik
    Member
    Posted 10 years ago #

    I split the word count off into it's own function and it works perfectly now. Go figure... :-/

  28. NuclearMoose
    Member
    Posted 10 years ago #

    Can someone please confirm if this hack works with 1.01 RC1?
    Has anybody written this up and posted it on their site? If so, can it please be added to the Wiki?
    Thanks.
    Craig.

  29. Nick Momrik
    Member
    Posted 10 years ago #

    I have this function in my hack file and it works in 1.01 RC1
    function get_word_count() {
    global $wpdb, $tableposts;
    $words = $wpdb->get_results("SELECT post_content FROM $tableposts");
    foreach ($words as $word) {
    $post = strip_tags($word->post_content);
    $post = explode(' ', $post);
    $count = count($post);
    $totalcount = $count + $oldcount;
    $oldcount = $totalcount;
    }
    echo number_format($totalcount);
    }

  30. Nick Momrik
    Member
    Posted 10 years ago #

    Added to Wiki.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.