Addpixel / KirbyComments

[Kirby 2] File-based comments stored as subpages for the Kirby CMS.
MIT License
68 stars 5 forks source link

Support for threaded comments #27

Closed jenstornell closed 7 years ago

jenstornell commented 7 years ago

Like nested comments.

florianpircher commented 7 years ago

Threaded comments are currently not supported, but once custom fields (see #23) are supported you will be able to implement replies using a custom reply-to field which stores the ID of the comment you are replying to. I will add an nestByField() method for more convenience in the front-end.

// custom comment rendering code:
function renderComment($comment) {
  echo $comment->message();

  if ($comment->hasNestedComments()) {
    foreach ($comment->nestedComments() as $child) {
      renderComment($child);
    }
  }
}

// nest comment by custom field
$nestedComments = $page->comments()->nestByField('reply-to');

foreach ($nestedComments as $comment) {
  renderComment($comment);
}
florianpircher commented 7 years ago

Comment nesting has been implemented and tested. Shipping soon with v1.5.

florianpircher commented 7 years ago

Version 1.5.0 is live and on master. You can try out nested comments on the demo page.

florianpircher commented 7 years ago

For more info have a look at

mciszczon commented 6 years ago

Could you please take a look at your demo page for nested comments? It's only showing the Kirby's debug screen (which is not very safe on a public server, by the way).

And while we're at it: documentation on nesting comments is almost non-existent, I can't seem to get it to work. Would it be possible to extend it or at least get a source code of your demo? Then I could figure it out.

Thanks.

florianpircher commented 6 years ago

Thank you for reporting the Kirby debug screen! The error has now been fixed (PHP 7.2 comparability issue) and will be included in the next release.

You can download a minimal version of the demo page as an example snippet from the Replies demo-page (https://kirby-comments.addpixel.net/demos/replies) and enable it by adding the following code to your config.php:

c::set('comments.custom-fields', array(
    array('name' => 'reply-to')
));

Nested comments are implemented using Custom Fields and the NestedComment class. If you have any further questions, feel free to ask them.