My projects

Recent comments and Schema.org

Build a recent-comments list and control structured output for visible published content.

Lesson 18 / 22 · Commentail 1.3.2

For a homepage or sidebar list, use commentail_recent rather than embedding a whole discussion. The tag returns a limited presentation dictionary for your markup.

Render a list

In the target template:

django
{% load i18n commentail_tags %}
{% commentail_recent limit=5 as recent_comments %}
<ul>
{% for comment in recent_comments %}
  <li>
    <a href="{{ comment.url }}">{{ comment.author_name }}: {{ comment.text|truncatechars:120 }}</a>
    <span>{{ comment.target_title }}</span>
    <time datetime="{{ comment.published_at|date:'c' }}">{{ comment.published_at|date:'SHORT_DATETIME_FORMAT' }}</time>
  </li>
{% empty %}
  <li>{% trans "No comments yet." %}</li>
{% endfor %}
</ul>

Text remains escaped. truncatechars:120 affects only this list. Results contain no email addresses or protected tokens. For root messages from one exact Page:

django
{% load commentail_tags %}
{% commentail_recent limit=3 page=page include_replies=False as recent_comments %}

Pass integers and booleans without quotes. page=page selects that Page, not descendants. limit=0 returns no entries. By default the list includes recent published comments and replies from accessible discussions on the current Site. Pending, rejected, hidden and deleted messages are excluded.

Diagnose an empty list

The template needs request from the context processor. A Page must be live, accessible, within the Site root and use the ordinary discussion widget in its template. Recent-comments alone does not enable a Page discussion. Objects use their registered adapters.

Selection depends on the visitor. Do not shared-cache the list or widget, or override private,no-store with public CDN caching. That could expose information from restricted content.

Control structured output

The widget defaults to both Comment microdata and JSON-LD for rendered published messages. To use JSON-LD only:

python
COMMENTAIL = {"default": {"STRUCTURED_DATA": "json_ld"}}

Choices are both, json_ld, microdata and off. When integrating a host Schema.org graph, intentionally disable duplicate output. In an overridden block.html retain {% commentail_json_ld structured_comments %} when using the built-in serializer. Do not concatenate JSON with safe.

Inspect page source for private messages, email addresses and protected URLs. Do not invent rating stars or Review data. Valid Schema.org does not guarantee a search feature or higher rankings.

Related lessons

Related documentation

Was this article useful?

Comments 0

Name: up to 40 characters.

After submitting, we will email you a link to confirm your email address.

Maximum 5000 characters.

No published comments yet.