Check for entry comments

Sunday, May 23, 2004

By default in EE the comments are shown in an ordered list, like so:

<ol>
{exp:comment:entries}
<li>{comment}
<div class=“posted”>Posted by {url_or_email_as_author}
on {comment_date format=’%m/%d’} 
at {comment_date format=’%h:%i %A’}</div></li>
{/exp:comment:entries}
</ol>

When there are no comments, the <ol></ol> tags are still displayed, even if there is nothing in between them. This does not validate as XHTML strict.

So, I used php to help me determine whether or not an entry has comments. Then, the <ol></ol> tags are displayed only when there are comments.

First, I enabled php in my weblog/comments template. Right before the closing {/exp:weblog:entries} tag, I added the following php code:

<?php
/* Does the entry have comments or not? */
$comment_total = {comment_total};
$has_comments = ($comment_total > 0) ? true : false;
?>

The first line stores the total comments number {comment_total} into a php variable. The second line checks whether that number is greater than 0 - if it is, the entry has comments.

Next:

<?php if ( $has_comments ) { ?>
<ol>
{exp:comment:entries}
<li>
{comment}
<div class=“posted”>Posted by {url_or_email_as_author}  
on {comment_date format=’%m/%d’} 
at {comment_date format=’%h:%i %A’}</div>
</li>
{/exp:comment:entries}
</ol>
<?php } ?>

Comments & Trackbacks

Post a comment.

The trackback URL for this entry is:

Avatar for Lynda

1. Lynda United States said:

on May 26 2004 @ 11:54 PM

Hmmm. Comments aren’t shown in an ordered list for me. That’s just as well though since it would have irritated me. smile

Avatar for Yvonne

2. Yvonne Canada said:

on May 27 2004 @ 01:28 AM

Yeah, they were in an ordered list on the default template I had chosen at first (#7 I think?) I ended up changing the template of course (and keeping the ordered list) but I posted it in case other people found that problem too.

Avatar for Lynda

3. Lynda United States said:

on May 27 2004 @ 02:43 PM

Ohhhhh. I didnt even look at the default templates. hehe.

Post a Comment

Commenting is not available in this weblog entry.

Live Preview

Avatar

Comment Author

Jan 08 2009 @ 06:10 PM