Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Code optimising: comparing timestamp variables
Hi.
I’ve decided I want to populate the http-equiv last-modified
meta data for article lists. The logic I’m using is to find which article was most recently posted or modified and then squirt the timestamp into the meta data accordingly. I seem to have achieved what I want to do: it involves 4 forms and a chunk of code. I’m keen to better understand txp:variable
and keeping things lean, so I figured I could post my code up here for scrutiny from other pairs of eyes.
Before I jump into the forms and code I’m using, here’s my workflow:
- set a variable of the most recently modified article timestamp in epoch format
- set a variable of the most recently posted article timestamp in epoch format
- compare the two using
aks_var
- depending on which is more recent, print the modified/posted timestamp in human-readable format for the
http-equiv last-modified
meta data
So, here goes. My article forms:
article_modified_epoch (outputs the <txp:modified>
timestamp in UNIX epoch format)
<txp:modified format="%s" gmt="1" />
article_posted_epoch (outputs the <txp:posted>
timestamp in UNIX epoch format)
<txp:posted format="%s" gmt="1" />
article_modified (outputs the <txp:modified>
timestamp in http-equiv last-modified
-friendly format)
<txp:modified format="%Y-%m-%d@%H:%M:%S GMT" gmt="1" />
article_posted (outputs the <txp:posted>
timestamp in http-equiv last-modified
-friendly format)
<txp:posted format="%Y-%m-%d@%H:%M:%S GMT" gmt="1" />
Here’s the page code that I’m using to call the forms:
<txp:if_article_list>
<txp:variable name="article_list_last_modified_epoch" value='<txp:article form="article_modified_epoch" limit="1" sort="LastMod desc" />' />
<txp:variable name="article_list_last_posted_epoch" value='<txp:article form="article_posted_epoch" limit="1" sort="Posted desc" />' />
<txp:aks_var name="article_list_last_comparison" value='<txp:variable name="article_list_last_modified_epoch" />' calc='> <txp:variable name="article_list_last_posted_epoch" />' />
<txp:if_variable name="article_list_last_comparison" value="1">
<meta http-equiv="last-modified" content='<txp:article form="article_modified" limit="1" sort="LastMod desc" />' />
<txp:else />
<meta http-equiv="last-modified" content='<txp:article form="article_posted" limit="1" sort="Posted desc" />' />
</txp:if_variable>
</txp:if_article_list>
As I say, that appears to work, but I’m all for keeping things slick and fast, so any pointers for streamlining would be greatly appreciated.
As ever, thank you in advance, and best wishes to you all.
Last edited by gaekwad (2013-02-28 17:50:33)
Offline