Comment Functions

Comments can be placed on Content Pages and Blogs using the Ajax interface and displayed using the Ajax or Smarty Methods when required.

This article describes the Smarty methods available to you and how to use them, providing details and examples available in the Aurora Demo Front-end Templates.

Overview

Using the Smarty methods described in this article, you can list comments on any template in Aurora where you have access to the Content ID or the Page or Blog you wish to use.

🚧

If you want to know how to add new comments, you can use the form provided in the example templates featured in this article, however the process is actually using the Ajax methods detailed in the Ajax Content Comments article.

Listing Comments (contentCommentsFind)

It is possible to list your Page/Blog Comments anywhere in Aurora using the contentCommentFind function.

Accepted Parameters

ParameterValuesDefaultDescription
content_idPositive IntegerThe Internal ID Aurora uses to identify a Content Item (Blog Post/Content Page).Yes
itemStringblog_postsThis is the name of the variable you would like the results of your data placed in. For example, if you set this to "posts" then the items returned by this method will be loaded into a $posts template variable.No
pageNon-negative Integer1The number of the page of results you would like to have returned.

The number of items returned per page defaults to the value specified in the "Posts per page" setting located under Store -> Settings -> Blog, but can be overridden using the "items_per_page" parameter if desired.
No
items_per_pagePositive Integer20The number of content items to return per page.

This should be used to retrieve a particular number of items instead of any 'limit' variable. So if you require a list of 50 Content Items, then simply set this to 50 and do not provide a 'page' value (or do provide a 'page' value but set it to 1).
No
limitPositive Integer20The number of content items to return in this request.

The limit parameter has been made available for use along side the start parameter only, but it is recommended that the built-in paging (items_per_page and page) combination be used instead as this is far simpler in nature and provides better support for the automated paging values.
No
startPositive Integer1The number of the content items to start returning in this request.

e.g. If 3 is provided, then the 3rd item in the result set will be the first to be returned.

The start parameter has been made available for use along side the limit parameter only, but it is recommended that the built-in paging (items_per_page and page) combination be used instead as this is far simpler in nature and provides better support for the automated paging values.
No
order_by_ascendingBooleanfalseIf set to 'true', then the content items are returned in Ascending order, otherwise they are returned in Descending order.



In combination with the default value set for the "order_by" parameter, this method will return content items in descending date order, delivering the most recently created items first by default.
No

Data Returned

FieldValuesDescription
[ item ].xArray( content_comment )The data returned by this function is saved to the variable named in the item parameter.

This data takes the form of an array of content_comment (as described further down in this table).
[ item ]_total_itemsNon-negative IntegerThe total number of items found by this function is saved to the variable named in the item parameter with the addition of "_total_items".

For example, if you set item="posts" then your items will be found in a $posts template variable and the 'total items' will be stored in a $posts_total_items variable.



This is commonly used for showing how many results there are matching a particular query/search when paging, e.g. "1-20 of 650" where 650 is the value returned within the total_items variable.
[ item ]_more_availableBooleanWhether or not there are more items to be returned that were not returned by this request is saved to the variable named in the item parameter with the addition of "_total_items".

For example, if you set item="posts" then your items will be found in a $posts template variable and the 'more available' status will be stored in a $posts_more_available variable.



This is commonly used for deciding whether or not to show the "Next Page" link when listing Content Items.
[ item ]_number_of_pagesNon-negative IntegerThe number of pages available for your request is saved to the variable named in the item parameter with the addition of "_number_of_pages".

For example, if you set item="posts" then your items will be found in a $posts template variable and the 'more available' status will be stored in a $posts_number_of_pages variable.



This is most useful when simply using the default value for items_per_page, so that your calling script(s) can generate their paging as needed without the need to know the specifics about the limits in play.
content_commentContainerFor more details regarding the fields available here, please see the content_comment variable in the "get: Data Returned" section of the Ajax Content Comments article.

Example template code

For a complete example, please see the following template in the Aurora Demo Example Front-end Templates:

templates/example.com/blog/comments.tpl.html

👍

This template (or its content) can be included anywhere you wish to list Content Comments and supports the addition of new comments via Ajax.

The following is a very simple example just to illustrate how the function works.

{contentCommentsFind content_id=$page.id item="comments"}
{foreach from=$items item="info"}
	{if ($info.comment_approved == '1' AND $info.user_ip == $existing_ip) OR ($info.comment_approved == '2') OR ($smarty.session.user.user_type >= 1) }
<div class="template_blog_comments_box">
		{if $info.comment_approved == '1'}
	<div class="template_blog_moderation">Currently awaiting moderation</div>
		{/if}
	{$info.website|blog_comment_author_link:$info.name} said on {$info.date_created|strtotime|date:"`$config.blog_date_format` @ `$config.blog_time_format`"}<br />
	{$info.comment|escape:"html":"UTF-8"|nl2br}
</div>
	{/if}
{/foreach}

Related Aurora Demo Example Files
example.com/blog/comments.tpl.html
example.com/_js/blog.js