Sourcefabric Manuals

 English |  Español |  Français |  Italiano |  Português |  Русский |  Shqip

Newscoop 4.2 Cookbook

List of latest comments

The Newscoop internal statistics mechanism keeps track of the latest comments, and this mechanism can be used to create a list of the ten most recent comments on the site for all articles. The following code snippet is taken from The New Custodian's front page, from the sub-template _tpl/sidebar-most.tpl

Here is a screenshot:

This code snippet will:

  • List five articles, ordered by the latest comment, in descending order - regardless of the issue or section 
  • Set a constraint so that the article type is 'news'
  • Point to the latest comment for that article
  • List the nickname given by a commenter on a comment (with 'not registered' mark if user is not logged in, or with the link created of username to his profile page, is commenter was logged in)
  • Combine that with the name of the article they're commenting on, with link to full article page
{{ list_articles length="5" ignore_issue="true" ignore_section="true" order="byLastComment desc" constraints="type is news" }}

<li>{{ list_article_comments length="1" order="bydate desc"}}<b>{{ if $gimme->comment->user->identifier }}
<a href="http://{{ $gimme->publication->site }}/user/profile/{{ $gimme->comment->user->uname|urlencode }}">{{ $gimme->comment->user->uname }}</a>
{{ else }}
{{ $gimme->comment->nickname }} {{ #anonymous# }}
{{ /if }}</b>{{ /list_article_comments }} on <a href="{{ uri options="article" }}">{{ $gimme->article->name }}</a></li>
{{ /list_articles }}

Here is another example which will do the following:

  • List the ten most recent comments, regardless of article
  • Order the comments by date, in descending order
  • Provide the URI for the comment and the article's name
  • Return the count of article comments
  • Return an excerpt of the article comments, truncated to 400 characters
  • Return the date and time the comment was posted
{{list_article_comments length="10" ignore_article="true" order="byDate desc"}}
    <a href="{{url}}#comments">{{$gimme->article->name}}</a><sup>{{$gimme->article->comment_count}}</sup>
    <p>{{$gimme->comment->content|truncate:400}} <span>{{$gimme->comment->submit_date|camp_date_format:"%H:%i"}}</span></p>
{{/list_article_comments}}

Finally, here is a similar, but more limited approach. We will:

  • List the ten most recently-commented articles, ordered by last comment, in descending order, regardless of the issue and section they were published in
  • Return the article's URI
  • Return the article's name
  • Return the count of comments for the article
{{ list_articles length="10" order="byLastComment desc" ignore_issue="true" ignore_section="true" }}
  <a href="{{ url }}#comments">{{ $gimme->article->name }}</a><sup>{{ $gimme->article->comment_count }}</sup>
{{ /list_articles }}

To learn more about listing comments for one specific article and providing the comment form, read the chapter on Article Comments.

There has been error in communication with Booktype server. Not sure right now where is the problem.

You should refresh this page.