Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-01-08 23:42:12

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

<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

#3 2009-01-09 00:16:03

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

Re: <txp:if_modified> ?

Perfect! Love it!

Offline

#4 2009-01-09 00:17:52

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

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

Board footer

Powered by FluxBB