Snippet · Mecha CMS

Code snippet collection for developers.

Basic Recent Comments

Author: Taufik Nurrohman · 336 Views

Tweet

Show list of comments in reverse order by time.

Requires comment extension.

<?php

$_path = COMMENT;
$_chunk = 7;

echo '<h3>Recent Comments</h3>';
$_comments = [];
if ($_pages = File::explore([$_path, 'page'], true)) {
    echo '<ul>';
    foreach ($_pages as $_k => $_v) {
        $_comments[Path::B($_k)] = $_k;
    }
    if (!empty($_comments)) {
        krsort($_comments);
        foreach (Anemon::eat($_comments)->chunk($_chunk, 0) as $_comment) {
            $_comment = new Comment($_comment);
            echo '<li>';
            echo '<p>' . HTML::a($_comment->author, $_comment->url, false, ['rel' => 'nofollow']) . '</p>';
            echo '<p>' . To::snippet($_comment->content) . '</p>';
            echo '<p><em>' . $_comment->date->F2 . '</em></p>';
            echo '</li>';
        }
        echo '</ul>';
    } else {
        echo '<p>No comments yet.</p>';
    }
} else {
    echo '<p>No comments yet.</p>';
}

?>
  • $_chunk → How many comments you want to list.

0 Comments

No comments yet.