Methods
Page methods
$page->comments()
Returns all published comments of a page.
$page->comments(): Kirby\Cms\Structure
Return type
Example
<?php $commentList = $page->comments(); ?>
<ul>
<?php foreach($commentList as $comment): ?>
<li>
<?= $comment->authorname(); ?> wrote <?= $comment->content()->kt(); ?>
</li>
<?php endforeach(); ?>
</ul>
$page->commentCount()
Returns the number of published comments of a page.
$page->commentCount(): int
Return type
int
Example
<p>There are <?= $page->commentCount(); ?> published comments on this page</p>
$page->commentsAreEnabled()
Returns if the comment functionality of a page is enabled. It can be disabled in different ways.
$page->commentsAreEnabled(): bool
Return type
boolean
Example
<?php if($page->commentsAreEnabled()): ?>
<!-- Show the comment form -->
<?php endif; ?>
Site methods
$site->numberOfPendingComments()
Returns the number of pending comments from all pages.
$site->numberOfPendingComments(): int
Return type
int
Example
<p>There are <?= $site->numberOfPendingComments(); ?> comments waiting to be approved</p>
$site->numberOfSpamComments()
Returns the number of comments from all pages marked as spam.
$site->numberOfSpamComments(): int
Return type
int
Example
<p>There are <?= $site->numberOfSpamComments(); ?> spam comments waiting to be deleted</p>
$site->latestComments()
Returns the number of comments from all pages ordered by date.
$site->latestComments($limit: number, $showWebmentions: boolean): Structure
| Parameter | Default | Description |
|---|---|---|
| $limit | 5 | Number of comments |
| $showWebmentions | false | Also return Webmentions |
Return type
Example
<?php if($commentList = $site->latestComments(5): ?>
<?php foreach($commentList as $comment): ?>
<?= $comment->authorName(); ?>
<?php endforeach; ?>
<?php endif; ?>
$site->latestCommentsPerPage()
Returns the number of comments from all pages grouped by page ordered by date.
$site->latestCommentsPerPage($limit: number, $showWebmentions: boolean): Structure
Parameter
| Parameter | Default | Description |
|---|---|---|
| $limit | 5 | Number of comments |
| $showWebmentions | false | Also return Webmentions |
Return type
Example
<?php if($commentGroups = $site->latestCommentsPerPage(5): ?>
<?php foreach($commentGroups as $group): ?>
<?php foreach($group as $comment): ?>
<?= $comment->authorName(); ?>
<?php endforeach; ?>
<?php endif; ?>