Wed 19th Oct 2005
Interesting WordPress Smarty Functions
Posted late evening, filed under Blogsome , Smarty Templates.Here are some interesting Smarty equivalents of WordPress functions I hadn’t come across before:
{get_lastpostdate}or{get_lastpostmodified}- returns a timestamp, such as 2005-10-16 07:10:51 that contains the last post date.{get_lastcommentmodified}is identical, but for the last comment.{human_time_diff from=n to=n}- similar to a script I wrote about, and implemented. Limited in that it only does days, not any larger unit. Advantage: done by the server, doesn’t ‘flash’ changing text via JavaScript, neater than my Smarty version.{get_day_link}- much neater than the version I was using! Generates the URI as described. Also{get_page_link},{get_year_link},{get_month_link}and{get_feed_link}.{globalvar var=varname value=value}- makes a value a global PHP variable. Very interesting…
So this os the place to come for the good stuff?
2 days, 13 hours after the fact.
Yes.
2 days, 14 hours after the fact.
Hi!
Question #1:
This might seem like a dumb question, but what exactly should I do to get {human_time_diff from=n to=n} to work. What should i replace ‘n’ with?
Question #2:
How did you create the “Catchpa” thing?
I would be very greatful for an answer.
2 days, 17 hours after the fact.
The times you want to know the difference. The two tricks are a) it needs to be a time that is the number of seconds, and b) you cannot just use the Smarty function {the_time}, as functions cannot be nested. You’ll need to assign the result of the function to a Smarty variable first:
{capture name=comment_time}{comment_date d="U"}{/capture}{capture name=post_time}{the_time d="U"}{/capture}
{human_time_diff
from=$smarty.capture.post_time
to=$smarty.capture.comment_time}
(That last one can all go on the one line).
As for the Catchpa: I’ve written a post about it somewhere on this site. I’m not completely happy with it, as it seems to still be letting through some Comment Spam. I think I need to think more like a Comment Spammer before I rewrite it…
2 days, 19 hours after the fact.