ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

If One Comment, Show "Comment" Title. If Two Comments, Show "Comments" Title.

December 08, 2009 2:34pm

Subscribe [3]
  • #1 / Dec 08, 2009 2:34pm

    Big Skillet

    364 posts

    I need to setup an {if} statement that will show “1 Comment” when there is only one comment.  If there are multiple comments, the title should have an “S” on the end with the title being “2 Comments”.

    Is that possible?  Not sure how to do it…

    Thanks!

  • #2 / Dec 08, 2009 4:10pm

    Bob Sutton

    87 posts

    Have you tried something like this between your {exp:comment:entries} tags?

    <h5>{count} COMMENT{if count >1}S{/if}</h5>

    You could probably also test for count!= “0” and selectively display the comment counter or an alternate message like “Be the first to Comment about this Entry!”

  • #3 / Dec 08, 2009 4:39pm

    Big Skillet

    364 posts

    Thanks Bob!  That works great, but it also removes the “s” when there are no comments.  I need it to be “0 Comments” instead of “0 Comment”.  I tried modifying the if statement, but not luck…

  • #4 / Dec 08, 2009 4:43pm

    Ingmar

    29245 posts

    {count} comment{if count != 1}s{/if}

    😊

  • #5 / Dec 08, 2009 4:49pm

    Big Skillet

    364 posts

    Ahhh… I figured out why it wasn’t working.  I was trying to use “count”, but this case called for “comment_total”.

    Comment{if comment_total != 1}s{/if}

  • #6 / Dec 08, 2009 4:50pm

    Bob Sutton

    87 posts

    I don’t have time to run this in a live page that has comments, but it oughta work:

    <h5>{count} COMMENT{if count == 0 OR if count >1}S{/if}</h5>
  • #7 / Dec 08, 2009 4:51pm

    Big Skillet

    364 posts

    Thanks Bob & Ingmar… Problem solved.

  • #8 / Dec 08, 2009 4:57pm

    Bob Sutton

    87 posts

    You’re right. COUNT is the sequence where the Comment occurs in a Comment list for an entry. e.g. “This is Comment No. {count}.” My bad.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases