Keyword

Disable comments after x days

  • Steven Trooster
  • Steven Trooster's Avatar Topic Author
  • Offline
  • Premium Member
More
5 years 10 months ago - 5 years 10 months ago #170745 by Steven Trooster
Disable comments after x days was created by Steven Trooster
I've seen that spammers like to post in old articles, so they won't get noticed. Is there a way to disable comments to an article automatically after a number of days? Now I have to set / unset the comments per article, which is undoable since we post 10 articles a week.
And I don't want the comments already posted to disappear, just the form removed from the article.
Last edit: 5 years 10 months ago by Steven Trooster.

Please Log in or Create an account to join the conversation.

More
5 years 10 months ago #170749 by JoomlaWorks
Replied by JoomlaWorks on topic Disable comments after x days
You have 2 options here. Either enable moderation (no comments are auto-published) or add some PHP to check if the item was created more than 10 days ago and then hide the form entirely.

At the very top of your item.php override and after "defined('_JEXEC') or die;", add this inside the <?php ... ?> block:
$itemDate = strtotime($this->item->created);
$now = strtotime('now');
$diff = number_format(($now - $itemDate)/(3600*24));

"$diff" returns the difference in days between now and the time the item was created. So if you want to hide the comments form 10 days after an item was created, update the 2 instances of "<?php echo $this->loadTemplate('comments_form'); ?>" with:
<?php if ($diff <= 10): ?>
<?php echo $this->loadTemplate('comments_form'); ?>
<?php endif; ?>

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • Steven Trooster
  • Steven Trooster's Avatar Topic Author
  • Offline
  • Premium Member
More
5 years 10 months ago #170843 by Steven Trooster
Replied by Steven Trooster on topic Disable comments after x days
Moderation will have an extra burden on the admins.
Adding extra code to the template was something I was thinking too. Thank you for the code. That saves me some time.

Please Log in or Create an account to join the conversation.

More
5 years 10 months ago #170847 by JoomlaWorks
Replied by JoomlaWorks on topic Disable comments after x days
You're welcome :)

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

More
2 years 11 months ago #179726 by Bahman Shafigh
Replied by Bahman Shafigh on topic Disable comments after x days
Hi Fotis,
I have the same problem and want to change the php code for turning off K2 comments after a period of time. Your post is displaying just some area for reporting nothing else. I made an screenshot which is attached. Would you please post your answer again?
Many thanks in advance
Attachments:

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum