tips icon image

EE Insider Tips
Sponsored by Mijingo's EE 2 Screencasts

ExpressionEngine mini-howtos created by the EE Insider community.

Better handling of comment list and comment form display

User's avatar
  • Posted by Derek Hogue
  • February 13, 2010
  • 0 people have found this tip helpful.

First, I suggest making your comment form and comment list markup into distinct templates, which accept a single embedded variable (“weblog”). This allows you to reuse these templates wherever you allow comments on your site. Say these are located at embeds/comment_list and embeds/comment_form.

Then, use this code at the end of your entries, where you want comments to display:

{if comment_total "0" || allow_comments}
    {embed
="embeds/comment_list" weblog="blog"}
{
/if}

{if allow_comments}
    {embed
="embeds/comment_form" weblog="blog"}
{if
:else}
    
<class="no-comments">Comments are now closed.</p>
{/if} 

This technique circumvents the generic “Commenting is not available in this weblog entry” message that appears when comments are closed. Note that this must be placed within your weblog:entries loop.

Add Your Comment?

You must have an EE Insider account to post comments on Insider Tips. It's fast, easy and hassle-free.

Sign up now (or login).

Search EE Insider Tips
Sponsored By