scriptygoddess RSS Feed
 
 
 
 

How to have your comments line say different things depending on the number of comments

Long how to description… simple script.

(This script is specific to MT)

In Javascript:

<script language=javascript>
<!–
document.write('<a href="<$MTEntryLink$>#comments">')
if (<$MTEntryCommentCount$> == 0)
{
document.write(<b>'speak up</b></a>')
} else if (<$MTEntryCommentCount$> == 1)
{
document.write('<$MTEntryCommentCount$> <b>voice</b></a>')
} else if (<$MTEntryCommentCount$> > 1)
{
document.write('<$MTEntryCommentCount$> <b>voices</b></a>')
}
//–>
</script>

or in PHP:
<?
print('<a href="<$MTEntryLink$>#comments">');
if (<$MTEntryCommentCount$> == 0)
{
print('speak up</a>');
} else if (<$MTEntryCommentCount$> == 1)
{
print('<$MTEntryCommentCount$> voice</a>');
} else if (<$MTEntryCommentCount$> > 1)
{
print('<$MTEntryCommentCount$> voices</a>');
}
?>

8 Responses to “How to have your comments line say different things depending on the number of comments”

  1. 1
    Kristina:

    The php and javascript versions weren't working for me (possibly conflicting with the restricted posts hack). So I tried searching and found this MT plugin in the support forums and it worked beautifully! Just wanted to pass it on!

  2. 2
    joi:

    i really really adore this script, but im having trouble getting it to work… can someone post a sample of what that section of code should look like once inserted into the template? ive tried it several different ways, but either my links stay the same as before, or they disappear completely. do i need something MORE than this script, or should i just have this script between ?

    any help would be great! thanks :)

    -joi.

  3. 3
    cal:

    truly fabulous, jennifer, as always ;-)

  4. 4
    Richard Ames:

    Hi Goddess- I tryed your java script above, but keep getting "Unterminated script constant" error message after I try to load the page in my browser after rebuilding MT with the script in it. I haven't a clue what that error message means. I put the script between the &ltMTEntryIfAllowComments&gt tags as you said. Any ideas?

    -Richard.

  5. 5
    cal:

    i love this comment script….but was wondering, (due to my lack of javascripting skills)…

    if you could combine the above script with the following:

    <MTEntryIfAllowComments>
    | <a href="<$MTCGIPath$><$MTCommentScript$>?entry_id=<$MTEntryID$>" onclick="OpenComments(this.href); return false">Comments (<$MTEntryCommentCount$>)</a>
    </MTEntryIfAllowComments>

    this way i could keep the comments pop-up.
    thanks!

  6. 6
    Jennifer:

    Yes. Change this line in my code:

    document.write('<a href="<$MTEntryLink$>#comments">')

    to this:

    document.write('<a href="<$MTCGIPath$><$MTCommentScript$>?entry_id=<$MTEntryID$>" onclick="OpenComments(this.href); return false">')

    (of course my script needs to be put between the <MTEntryIfAllowComments> like you had)

    oh, and the PHP version – change this line in my code:

    print('<a href="<$MTEntryLink$>#comments">');

    to this:

    print('<a href="<$MTCGIPath$><$MTCommentScript$>?entry_id=<$MTEntryID$>" onclick="OpenComments(this.href); return false">');

  7. 7
    kristine:

    I just noticed that this tip was on the sg site :) Nah, I'm not slow LOL!

    here's a thread on the MT boards that has an SSI solution for this as well as the PHP and JS that Jenn put together initially :)

  8. 8
    Leann:

    Yea! Just what I've been looking for!

Categories

Archives

Bookmarks

WordPress Resources

Meta

ADVERTISEMENTS