Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-04-20 15:45:14

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 999
Website

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

#2 2009-04-20 16:34:49

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,453
Website GitHub

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

#3 2009-04-20 18:44:18

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 999
Website

Re: How do I display time left for comments on an article?

Thank you sir! Can’t wait to try this out!

Offline

Board footer

Powered by FluxBB