Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
How do I display time left for comments on an article?
Is there a way to display “X weeks/days left to post a comment” based on your “Disable After” settings?
Sorry if this has been covered before— I searched the FAQ and the forum, but I might have overlooked the correct search phrase.
Thanks!
Offline
Re: How do I display time left for comments on an article?
If you don’t mind PHP messing up your forms, this might do the job.
Comment time remaining:
<txp:php>
global $prefs;
if ($prefs['comments_disabled_after'] > 0) {
$now = time();
$posted = posted(array("format"=>"%s"));
$commex = strtotime("+".$prefs['comments_disabled_after']." days", $posted);
$rem = ceil(($commex-$now)/(24*60*60));
echo ($rem>0) ? $rem ." days" : 'out of time!';
} else {
echo "forever!";
}
</txp:php>
It can be tidied up by wrapping the whole lot in if_comments_allowed (or equivalent) to remove the problem of what happens if the time has already passed comments judgement day. I tried variables and stuff at first, but PHP seems simplest since (I don’t think) the comments_disabled_after value is available to a tag. I’m sure someone could pluginise this and improve on it.
Incidentally, some of the maths is possible with <txp:smd_cal_now />
if you happen to have smd_calendar lying around.
EDIT: that always gives results in days. A swift further bit of modulo arithmetic on the $rem
variable would convert to weeks+days.
Last edited by Bloke (2009-04-20 16:38:04)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Online
Re: How do I display time left for comments on an article?
Thank you sir! Can’t wait to try this out!
Offline