Show latest comments
Two snippets are available to display the most recently published comments. Additionally, two site methods are available that can be used to implement such a list.
(Since version 3.8)
Snippets
Latest Comments
To display a simple list of the last five comments, use the komments/latest-comments snippet:
<?php snippet('komments/latest-comments'); ?>
It displays a simple list showing the name of the authors and the title of the affected pages:
<ul class="latest-comments">
<li>
<span class="comment-author">AUTHOR NAME</span>
—
<a href="PAGEURL#COMMENTID">
Page Title
</a>
</li>
</ul>
You can customize the snippet by overriding it in your own snippets. To do this, create the file sites/snippets/komments/latest-comments.php and copy the content from the original file into it, then make your changes.
Latest Comment Pages
To display a list of the most recently commented pages, use the komments/latest-comment-pages snippet:
<?php snippet('komments/latest-comment-pages'); ?>
It displays a simple list showing the title of the affected pages, the number of comments, and the name of the last comment author:
<ul class="latest-comment-pages">
<li>
<a href="PAGEURL#COMMENTID">
<span class="comment-page-title">PAGETITLE</span>
<span class="comment-info">(COUNT, AUTHORNAME)</span>
</a>
</li>
</ul>
You can customize the snippet by overriding it in your own snippets. To do this, create the file sites/snippets/komments/latest-comment-pages.php and copy the content from the original file into it, then make your changes.
Site-Methods
To create your own list, you have two page methods at your disposal. Each of them returns a Kirby structure.
latestComments
Returns a simple Kirby structure with comments.
<?php dump($site()->latestComments()); ?>
The parameter limit controls the number of returned comments, and the parameter showWebmentions enables the inclusion of webmentions.
latestCommentsPerPage
Returns a Kirby structure grouped by page, including comments.
<?php dump($site()->latestCommentsPerPage()); ?>
The parameter limit controls the number of returned comments, and the parameter showWebmentions enables the inclusion of webmentions.