Log in

No account? Create an account

The S2 HowTo Journal

Tips, Tricks, and Tutorials for Basic S2 Customization

Previous Entry Share Flag Next Entry
[paidaccount] Displaying comment count in words instead of numerals
howto_user wrote in s2howto
Paid Accounts Only
The following tutorial requires creating and editing a custom style, which in turn requires a paid, permanent, or early adopter account. Please read What are the paid account benefits? and How do I buy a paid account? to learn about the paid account benefits and how to buy a paid account.

This function will change the display of your comment count from numerals to number (e.g. "12 comments" becomes "Twelve comments"). This will work up to a comment count of 99, after which the count will be displayed in numerals. However, this function will not work for layouts that do not call the CommentInfo::print_readlink() method, some of which are Smooth Sailing, Refried Paper, Unearthed, and Disjointed. If you are using one of these layouts, you will need to modify the code that prints the "Read Comments" link to use this function.

You will need to copy the following code into your theme layer, making sure to include everything:

function CommentInfo::print_readlink {
    var Page p = get_page();

    var string[] ones = ["Zero","One","Two","Three","Four","Five","Six","Seven","Eight","Nine"];
    var string[] teen = ["Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"];
    var string[] tenths = ["","","Twenty","Thirty","Forty","Fifty","Sixty","Seventy","Eighty","Ninety"];
    var string text;
    var string comment_text_s = "reply";
    var string comment_text_p = "replies";
    var int rest;
    var int elevens;

    if($.count>99) {
        $text = "" + $.count;
    } else {
        $rest = $.count / 10;
        $elevens = $.count % 10;
        if($rest>0) {
            if($rest==1) {
                $text = $teen[$elevens];
            } else {
                $text = $tenths[$rest] + ($elevens>0 ? "-" + $ones[$elevens] : "");
        } else {
            $text = $ones[$elevens];

    $text = $text + " " + (($.count==1) ? $comment_text_s : $comment_text_p);
    if($.screened) {
        $text = $text + " <b>$*text_month_screened_comments</b>";
    print safe """<a href="$.read_url">""" + $text + "</a>";

You can alter the text in orange to change the text displayed after the number of comments for both singular and plural text, respectively. Compile your layer, and it's ready to use. You will need to apply your theme layer via the Customize interface in order for your changes to take effect.

Originally written by nigi_atp and prissi with elements borrowed from a previous tutorial by gamble.

Comments Disabled:

Comments have been disabled for this post.