Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
<txp:if_modified> ?
Is there a way for Textpattern to test if the modified date is different from the posted date?
I’d like to present the date an article was last updated alongside the original publication date, but only for articles that have been modified.
Not a big deal if this doesn’t work— I could use a custom field, but that would require manual entry.
Thanks!
Offline
#2 2009-01-09 00:01:23
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: <txp:if_modified> ?
Would this work?
<txp:variable name="modified" value='<txp:modified />' />
<txp:if_variable name="modified" value='<txp:posted />'>
<!-- display nothing -->
<txp:else />
<txp:modified />
</txp:if_variable>
(Edit: trimmed the code a bit.)
Last edited by els (2009-01-09 00:03:56)
Offline
Re: <txp:if_modified> ?
Perfect! Love it!
Offline
Re: <txp:if_modified> ?
johnstephens wrote:
Is there a way for Textpattern to test if the modified date is different from the posted date?
Yep, Els’ code (as ever) would do the trick if you want a completely native solution. It’s genius.
As an alternative, if you happen to have smd_if lying around it can also do it using a small undocumented feature of PHP; namely the %s
(lower case ‘s’) format directive which returns the number of seconds since UNIX began:
<txp:smd_if field='<txp:modified format="%s" />' operator="gt" value='<txp:posted format="%s" />'>
<txp:modified />
</txp:smd_if>
Last edited by Bloke (2009-01-09 00:18:45)
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
Offline
Pages: 1