Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Configure the way comments are listed

Jimi Wikman

Recommended Posts

  • Owner

In the templates for your record, you will find a template named "Comments". In this template there is a snippet of code that display the comments list and in that snippet of code we can make some adjustments to how comments are show,

{{$commentCount=0; $timeLastRead = $record->timeLastRead(); $lined = FALSE;}}
				{{foreach $record->comments( NULL, NULL, 'date', 'asc', NULL, NULL, NULL, NULL, FALSE, isset( \IPS\Request::i()->showDeleted ) ) as $comment}}
					{{if !$lined and $timeLastRead and $timeLastRead->getTimestamp() < $comment->mapped('date')}}
						{{if $lined = TRUE and $commentCount}}
							<hr class="ipsCommentUnreadSeperator">
				{template="commentMultimod" app="core" group="global" params="$record"}


So in this snippet of code we want to look at this part:

{{foreach $record->comments( NULL, NULL, 'date', 'asc', NULL, NULL, NULL, NULL, FALSE, isset( \IPS\Request::i()->showDeleted ) ) as $comment}}

This snippet has a few variables that we can adjust to change the way our comments are shown. By default we see 'date' and 'asc' already defined. As you can see in the list below asc is the sorting order and date is what the list of comments are ordered by.

	 * Get comments
	 * @param	int|NULL			$limit					The number to get (NULL to use static::getCommentsPerPage())
	 * @param	int|NULL			$offset					The number to start at (NULL to examine \IPS\Request::i()->page)
	 * @param	string				$order					The column to order by
	 * @param	string				$orderDirection			"asc" or "desc"
	 * @param	\IPS\Member|NULL	$member					If specified, will only get comments by that member
	 * @param	bool|NULL			$includeHiddenComments	Include hidden comments or not? NULL to base of currently logged in member's permissions
	 * @param	\IPS\DateTime|NULL	$cutoff					If an \IPS\DateTime object is provided, only comments posted AFTER that date will be included
	 * @param	mixed				$extraWhereClause		Additional where clause(s) (see \IPS\Db::build for details)
	 * @param	bool|NULL			$bypassCache			Used in cases where comments may have already been loaded i.e. splitting comments on an item.
	 * @param	bool				$includeDeleted			Include Deleted Comments
	 * @param	bool|NULL			$canViewWarn			TRUE to include Warning information, NULL to determine automatically based on moderator permissions.
	 * @return	array|NULL|\IPS\Content\Comment	If $limit is 1, will return \IPS\Content\Comment or NULL for no results. For any other number, will return an array.
	public function comments( $limit=NULL, $offset=NULL, $order='date', $orderDirection='asc', $member=NULL, $includeHiddenComments=NULL, $cutoff=NULL, $extraWhereClause=NULL, $bypassCache=FALSE, $includeDeleted=FALSE, $canViewWarn=NULL )

By changing these variables, you can edit the way your comments behave. Since you do this in the templates, it means that you can have different templates for different databases that each have its own behavior.

Big shoutout to Nathan Explosion for helping with this one.


View full record

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Please sign in to comment

You will be able to leave a comment after signing in

Sign In Now

  • Create New...