Retired Documentation:  You are using the documentation for version 1.7.3 which was retired in 2013. Go here for the latest version documentation or check here for your available upgrades to the latest version.

Comment Entry Tag

The Comment Entries Tag enables you to show the user-submitted comments associated with your entries.

Note:  The Comment Entries Tag is intended for use in one of your "single entry" pages.  That is, a page that shows a single, specific weblog entry.  Therefore, your Comment page must be linked to from within your Weblog entries using the URL Title Path variable or the Entry ID Path variable, so that the comments can be associated to a specific entry.  You may also combine Comments and Trackbacks together in an integrated display.

Here is a basic example showing how you might use the comment tag:

{exp:comment:entries sort="asc" limit="20"}

{comment}

<p>By {name} on {comment_date format="%Y %m %d"}</p>

{/exp:comment:entries}

Please note that the comment entries tag should not typically be nested inside of a standard {exp:weblog:entries} tag.

Parameters

dynamic=

dynamic="off"

The weblog and comment display engines set some parameters dynamically, based on what is in the URL. There are times, however, where you do not want the parameters affected by what the URL contains. To override the dynamic nature of the comment tag, use dynamic="off".

This is often useful if you want to list comments in a "sidebar" on your site and have them always be the same ones regardless of which page on your site you visit (main page, archives, comments, etc.). Using this, you can create a "recent comments" list. By setting dynamic="off" you will ensure that the list is not affected by anything passed in the URL.

When dynamic is set to 'off', pagination will still function using an 'N' as a pagination indicator in the url rather than the standard 'P' indicator.

entry_id=

entry_id="24"

You can hard code the comment entries tag to show comments for a specific weblog entry by its entry ID.

NOTE: This parameter takes precedence over any entry specified dynamically in the URL, so when using this parameter you will want to make sure it is clear to the user which entry the displayed comments belong to.

limit=

limit="30"

Allows you to limit the number of comments. The limit will default to 100 comments if a value is not specified. If you are using pagination then this will determine the number of comments shown per page.

orderby=

orderby="date"

The "order" parameter sets the display order of the comments. Setting options for this parameter include:

If you are combining the display of comments and trackbacks, then you may only set this parameter to date.

paginate=

paginate="top" paginate="bottom" paginate="both"

This parameter is for use with entry pagination and determines where the pagination code will appear for your comments:

  1. top: The navigation text and links will appear above your list of comments.
  2. bottom: The navigation text and links will appear below your list of comments.
  3. both: The navigation text and links will appear both above and below your list of comments.

If no parameter is specified, the navigation block will default to the "bottom" behavior.

paginate_base=

paginate_base="site/index"

This tells ExpressionEngine to override the normal pagination link locations and point instead to the explicitly stated template group and template.

show_expired=

show_expired="yes"

You can determine whether you wish for comments on "expired" entries to be included.

sort=

sort="asc" sort="desc"

The sort order can be "asc" (ascending order or "oldest item first" for dates) or "desc" (descending order or "newest item first" for dates). If you do not use a sort order the default is desc.

url_title=

url_title="my_wedding"

You can hard code the comment entries tag to show comments for a specific weblog entry by its URL title.

NOTE: This parameter takes precedence over any entry specified dynamically in the URL, so when using this parameter you will want to make sure it is clear to the user which entry the displayed comments belong to.

weblog=

weblog="which"

From which weblog to show the comments (will show comments from any weblog if no weblog is specified). Additionally, you can use the pipe character to separate multiple weblogs:

weblog="weblog1|weblog2|weblog3"

Or you can add the word "not" (with a space after it) to exclude weblogs:

weblog="not weblog1|weblog2|weblog3"

The weblog= parameter can have some security implications. If you do not use this parameter then it is possible that people could see comments for a weblog entry that they otherwise would not have access to. If you use multiple weblogs and want to make sure only certain people can see certain content, then you're encouraged to make use of this parameter.

Variables

absolute_count

{absolute_count}

The absolute "count" out of the current comment being displayed by the tag, including those comments on previous pages (if using pagination).

If five entries are being displayed per page, then for the fourth entry on the second page the {absolute_count} variable would have a value of "9".

author

{author}

The comment author's screen name, if a member; otherwise, this variable will display the name submitted with the comment.

<a href="http://example.com/index.php/member/{author_id}/">{author}</a>

author_id

{author_id}

The ID corresponding to the comment author's member profile. This is only applicable if the comment was left by a registered member. Non-registered commenters will return a zero (0).

This can be useful for creating links to the commenter's member profile:

<a href="http://example.com/index.php/member/{author_id}/">{name}</a>

aol_im

{aol_im}

The author's AOL IM account name

avatar_image_height

{avatar_image_height}

The height of the avatar image associated with the entry's author. Typically used as such:

{if avatar}
<img src="{avatar_url}" width="{avatar_image_width}" height="{avatar_image_height}" alt="{author}'s avatar" />
{/if}

avatar_image_width

{avatar_image_width}

The width of the avatar image associated with the entry's author. Typically used as such:

{if avatar}
<img src="{avatar_url}" width="{avatar_image_width}" height="{avatar_image_height}" alt="{author}'s avatar" />
{/if}

avatar_url

{avatar_url}

The URL to the avatar image associated with the entry's author. Typically used as such:

{if avatar}
<img src="{avatar_url}" width="{avatar_image_width}" height="{avatar_image_height}" alt="{author}'s avatar" />
{/if}

blog_title

{blog_title}

This variable simply displays the content from the "Full Weblog Name" setting of the weblog that the comment belongs to.

comment

{comment}

The body of the comment

comment_auto_path

{comment_auto_path}

This variable is replaced by the URL set in the "Comment Page URL" preference under Admin > Weblog Management. No entry id, URL Title, or other information is included; this is simply the exact URL from the preference.

comment_entry_id_auto_path

{comment_entry_id_auto_path}

This variable is replaced by the URL set in the "Comment Page URL" preference under Admin > Weblog Management. The ID number of the entry will be automatically added. For example, this:

<a href="{comment_entry_id_auto_path}">my entry</a>

Would be rendered like this:

<a href="http://example.com/index.php/weblog/comments/234/">my entry</a>

comment_id

{comment_id}

The ID associated with the comment

comment_site_id

{comment_site_id}

The Site ID for the comment.

comment_url_title_auto_path

{comment_url_title_auto_path}

This variable is replaced by the URL set in the "Comment Page URL" preference under Admin > Weblog Management. The URL Title of the entry will be automatically added. For example, this:

<a href="{comment_url_title_auto_path}">my entry</a>

Would be rendered like this:

<a href="http://example.com/index.php/weblog/comments/ice_cream/">my entry</a>

count

{count}

The "count" out of the current comment being displayed by the tag on the current page.

If five entries are being displayed per page, then for the fourth entry on the page the {count} variable would have a value of "4".

email

{email}

The comment author's email address, if specified.

entry_author_id

{entry_author_id}

The member ID for the creator of the entry whose comments are being displayed.

entry_id

{entry_id}

The ID number of the entry

entry_id_path

{entry_id_path='weblog/comments'}

The URL to the specified template. The ID number of the entry with which the comment is associated will be automatically added. For example, this:

<a href="{entry_id_path='weblog/comments'}">my entry</a>

Would be rendered like this:

<a href="http://example.com/index.php/weblog/comments/234/">my entry</a>

icq

{icq}

The author's ICQ IM user identification number

interests

{interests}

The author's "interests" as entered in their profile

ip_address

{ip_address}

The IP address of the commenter

location

{location}

The author's location as entered in their profile

member_search_path

{member_search_path='search/results'}

This variable is replaced by a URL that passes the author's member name to your search results Template. In this way, you can display all entries made by the author. You should specify the Template_Group/Template that you use to display search results. For example:

<a href="{member_search_path='search/results'}">View entries by this member</a>

msn_im

{msn_im}

The author's MSN IM account name

occupation

{occupation}

The author's occupation as entered in their profile

name

{name}

Name of the author

paginate=

paginate="top" paginate="bottom" paginate="both"

This parameter is for use with entry pagination and determines where the pagination code will appear for your gallery entries:

  1. top: The navigation text and links will appear above your list of entries.
  2. bottom: The navigation text and links will appear below your list of entries.
  3. both: The navigation text and links will appear both above and below your list of entries.

If no parameter is specified, the navigation block will default to the "bottom" behavior.

permalink

{permalink}

The URL to the actual comment with anchor. Put this variable in a link:

<a href="{permalink}">permanent link</a>

photo_url

{photo_url}

This variable supplies the URL to the member photo (if you have that option enabled and the member has uploaded their photo). It is intended for use in an image tag.

photo_image_height

{photo_image_height}

This variable supplies the height of the member photo. It is intended for use in an image tag.

photo_image_width

{photo_image_width}

This variable supplies the width of the member photo. It is intended for use in an image tag.

signature

{signature}

The signature associated with the entry's author. Typically used as such:

{if signature}
<p>{signature}</p>
{/if}

signature_image_height

{signature_image_height}

The height of the signature image associated with the entry's author. Typically used as such:

{if signature_image}
<img src="{signature_image_url}" width="{signature_image_width}" height="{signature_image_height}" alt="{author}'s signature" />
{/if}

signature_image_url

{signature_image_url}

The URL to the signature image associated with the entry's author. Typically used as such:

{if signature_image}
<img src="{signature_image_url}" width="{signature_image_width}" height="{signature_image_height}" alt="{author}'s signature" />
{/if}

signature_image_width

{signature_image_width}

The width of the signature image associated with the entry's author. Typically used as such:

{if signature_image}
<img src="{signature_image_url}" width="{signature_image_width}" height="{signature_image_height}" alt="{author}'s signature" />
{/if}

switch=

{switch="option_one|option_two|option_three"}

This variable permits you to rotate through any number of values as the entries are displayed. The first entry will use "option_one", the second will use "option_two", the third "option_three", the fourth "option_one", and so on.

The most straightforward use for this would be to alternate colors. It could be used like so:

{exp:comment:entries}
<div class="{switch="one|two"}">
<h1>{name}</h1>
{comment}
</div>
{/exp:comment:entries}

The entries would then alternate between <div class="one"> and <div class="two">.

Multiple instances of the {switch=} tag may be used and the system will intelligently keep track of each one.

title

{title}

The title of the weblog entry with which the comment is associated.

total_results

{total_results}

The total number of comments being displayed by this tag on the current page.

total_comments

{total_comments}

The total number of comments for this tag on all pages.

url

{url}

The author's raw URL, if it exists

url_as_author

{url_as_author}

Hyperlink pointing to the URL (if it exists) with the author name as the link title. If the URL does not exist simply the name is returned.

url_or_email

{url_or_email}

URL if it exists, otherwise the email address

url_or_email_as_author

{url_or_email_as_author}

Hyperlink or email link as author screen_name (or username if they haven't specified a screen name)

url_or_email_as_link

{url_or_email_as_link}

Same as above only it will display the URL or email address as a link

url_title_path

{url_title_path='weblog/comments'}

The URL to the specified template. The "url title" of the entry with which the comment is associated will be automatically added. For example, this:

<a href="{url_title_path='weblog/comments'}">permalink</a>

Would be rendered like this:

<a href="http://example.com/index.php/weblog/comments/ice_cream/">permalink</a>

weblog_id

{weblog_id}

The ID number of the actual weblog

yahoo_im

{yahoo_im}

The author's Yahoo IM account name

Custom Member Fields

All custom member profile fields can be accessed using the "short name" of the field:

{age}
{gender}
{zodiac}
etc..

These are totally dynamic in that any profile field you create for your members will automatically be available by its "short name" as a variable.

Single Variable Dates

Several date variables are available for use. As with other date variables, these require the "format" parameter in order to define how the date should be displayed. See the date variable formatting page for more information.

comment_date

{comment_date format="%Y %m %d"}

The date of the comment.

edit_date

{edit_date format="%Y %m %d"}

The date on which the comment was edited.

gmt_comment_date

{gmt_comment_date format="%Y %m %d"}

The date of the comment but not localized for the user.

Conditionals

Conditionals work in comments:

{if name=="bozo"}

You've got a big nose!

{/if}

if avatar

{if avatar}
content
{/if}

This special conditional lets you conditionally display content if the current entry's author has an avatar image specified.

{if avatar}
<img src="{avatar_url}" width="{avatar_image_width}" height="{avatar_image_height}" alt="{author}'s avatar" />
{/if}

if is_ignored

{if is_ignored}
content
{/if}

This conditionals allows you to show (or hide) specific content if the comment was made by a member on the logged-in user's ignore list. A simplified example of how this might be used is:

{exp:comment:entries}

{if is_ignored}You are ignoring {author}.{/if}

<div {if is_ignored}style="display: none;"{/if}>{comment}</div>

{/exp:comment:entries}

Or you can use Javascript to allow the user to read the comment if they wish:

<script type="text/javascript">
<!--

function showHideComment(el)
{
    if (document.getElementById(el).style.display == "block")
    {
        document.getElementById(el).style.display = "none";
    }
    else
    {
        document.getElementById(el).style.display = "block";
    }
}
//-->
</script>

{exp:comment:entries}

{if is_ignored}
    <p><a href="#" onclick="showHideComment('{comment_id}')">View / Hide</a> comment from ignored member: {author}</p>
{/if}

<div id="{comment_id}" {if is_ignored}style="display: none;"{/if}>{comment}</div>

{/exp:comment:entries}

Important:  Avoid using Template Caching on any Template containing this conditional. If you do not avoid caching, then data will not be dynamic for each user. Instead, whoever happens to load the page when it is cached will have their ignore list applied to everyone until the cache expires.

if no_results

{if no_results}
content
{/if}

You may use this conditional for displaying a message in the case when no comments are returned. The contents inside of the conditional will be displayed in cases where there are no results returned for the tag.

{if no_results}

<p>There are no comments for this entry yet.</p>

{/if}

Further, you may specify that another Template be shown in a case when there are no results. In order to do that, you must use the redirect= variable:

{if no_results}
{redirect="site/noresult"}
{/if}

if signature_image

{if signature_image}
content
{/if}

This special conditional lets you conditionally display content if the current entry's author has a signature image specified.

{if signature_image}
<img src="{signature_image_url}" width="{signature_image_width}" height="{signature_image_height}" alt="{author}'s signature" />
{/if}

Comment Submission Form

{exp:comment:form}

{/exp:comment:form}

There is one required parameter in the comment form but only if you want to use the preview feature:

{exp:comment:form preview="weblog/preview"}

The "preview" parameter specifies the template group/template in which the preview will be shown. More on previewing later.

The comment form is created pretty much like a normal form, only you don't specify the opening and closing form tags. There are a few variables that are required in order to enable people's personal information (name, email, url, etc.) to appear in the form. Here's how the comment form is typically created:

{exp:comment:form preview="weblog/preview"}

{if logged_out}

<p>Name: <input type="text" name="name" value="{name}" size="50" /></p>

<p>Email: <input type="text" name="email" value="{email}" size="50" /></p>

<p>Location: <input type="text" name="location" value="{location}" size="50" /></p>

<p>URL: <input type="text" name="url" value="{url}" size="50" /></p>

{/if}

<p><textarea name="comment" cols="70" rows="10">{comment}</textarea></p>

<p><input type="checkbox" name="save_info" value="yes" {save_info} /> Remember my personal information</p>

<p><input type="checkbox" name="notify_me" value="yes" {notify_me} /> Notify me of follow-up comments?</p>

<input type="submit" name="submit" value="Submit" />
<input type="submit" name="preview" value="Preview" />

{/exp:comment:form}

Notes:
The conditional variable {if logged_out} allows the system to show the short form (textarea only) if the user is a logged in member. We recommend you use the form this way because if a member is logged in, their personal data is fetched automatically.

Notice the variables in the "value" form fields? These allow us to show the user's information in the form automatically if they click the "remember personal info" option.

Top of Page