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.

Number of Comments Posted Header

August 24, 2011 1:33pm

Subscribe [3]
  • #1 / Aug 24, 2011 1:33pm

    Terence Hall

    15 posts

    I’m trying to show the number of comments posed for an article.  However, when I use limit=“1” (keeping the h3 tag from replicating) it always shows “1 comment” even if there are more comments.  Here is the code:

    {exp:comment:entries channel="features" limit="1"}
        <h3>Showing {total_results} Comment{if total_results>1}s{/if}</h3>
    <p>{/exp:comment:entries}

    Any idea how I can fix this?

    Thanks

  • #2 / Aug 24, 2011 2:13pm

    Mark Bowen

    12637 posts

    Hi Terence,

    As you have used the limit=“1” parameter then ExpressionEngine is correct in showing {total_results} as 1 as you have specifically made it do that in using that parameter.

    As per the Comment Entries documentation here it states that the {total_results} variable shows the total number of comments being displayed by the tag on the current page. As you have limited it to 1 that is why you are seeing this happening.

    To get around this you could either do this :

    {exp:comment:entries channel="features"}
    
    {if count == "1"}
    <h3>Showing {total_results} Comment{if total_results>1}s{/if}</h3>
    <p>{/if}</p>
    
    <p>{/exp:comment:entries}

    This should work to get you what you want however if there are a lot of comments in that channel then it might be overkill using that tag to do this.

    Another way would be to utilise the {comment_total} variable which is part of the Channel Entries Tag. I’m guessing that you will be showing this information on the same page which contains a Channel Entries Tag so here you won’t be pulling all the comments just to get at that information.

    If that won’t work then it might be best to use a simple SQL query in order to get the information you need instead.

    Hope that helps a bit.

    Best wishes,

    Mark

  • #3 / Aug 25, 2011 12:36am

    Terence Hall

    15 posts

    Mark…thanks a lot.  This worked PERFECTLY!

  • #4 / Aug 25, 2011 1:02am

    Dan Decker

    7338 posts

    Terence,

    I’m happy to see that Mark was able to get you all sorted out. Please start a new thread any time you need assistance in the future.

    Cheers,

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

ExpressionEngine News!

#eecms, #events, #releases