- Posts: 130
COMMUNITY FORUM
Disable comments after x days
- Steven Trooster
- Topic Author
- Offline
- Premium Member
Less
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.
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.
- JoomlaWorks
- Offline
- Admin
Less
More
- Posts: 6218
5 years 10 months ago #170749
by JoomlaWorks
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
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:
"$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:
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
- Topic Author
- Offline
- Premium Member
Less
More
- Posts: 130
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.
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.
- JoomlaWorks
- Offline
- Admin
Less
More
- Posts: 6218
5 years 10 months ago #170847
by JoomlaWorks
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
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.
- Bahman Shafigh
- Offline
- New Member
Less
More
- Posts: 1
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
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
Please Log in or Create an account to join the conversation.