1

I'm trying to only output the heading "Comments" when there are actually comments for a blog post.

Here's what I have:

{if total_comments >= 1}<h3>Comments</h3>{/if}
{exp:comment:entries sort="asc" limit="20"}
    <div class="text-block">
        <p>{comment}</p>
        <p id="author">By {name} on {current_time format="%F %d %Y"}</p>
    <hr>
    </div>
{/exp:comment:entries}

Any help is much appreciated!

6

Before closing the Channel Entries tag, you can use the comment_total variable. Or if that does not work with your markup, you can use count conditionals in the Comment Entries tag (not nested inside your Channel Entries tag):

{exp:comment:entries sort="asc" limit="20"}
    {if count == 1}<h3>Comments</h3>{/if}
    <div class="text-block">
        <p>{comment}</p>
        <p id="author">By {name} on {current_time format="%F %d %Y"}</p>
    <hr>
    </div>
{/exp:comment:entries}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.