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 } ?>
Nov 20 2008 @ 01:51 PM
Comments & Trackbacks
Post a comment.
The trackback URL for this entry is:
1. Lynda
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.
2. Yvonne
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.
3. Lynda
said:
on May 27 2004 @ 02:43 PM
Ohhhhh. I didnt even look at the default templates. hehe.