Display the published and modified dates

This tip will display the published date and, only if article has been changed, the last modified date article. There are two methods here, both of which require some PHP.

Method #1

You can place the following code in within your article form where you want to display the dates, or alternatively directly into your page template.

<p class="published"> By <txp:author /> on <txp:posted /> <txp:php> $changed = modified(array( 'format'=>'%m %d %Y – %H:%I')); echo $changed == posted(array('format'=>'%m %d %Y - %H:%I')) ? '' : '| Modified on '.$changed.' by '.safe_field("RealName", "txp_users", "name='".safe_field("LastModID", "textpattern", "ID='".$thisarticle['thisid']."'")."'");</txp:php>

Method #2

This method, based on a contribution by Els Lepelaars in this thread, uses Textpattern’s in-built if_variable tag:

<p class="published">Published by <txp:author /> on <txp:posted format="%m %d %Y - %H:%I" /> <txp:variable name="modified" value='<txp:modified />' />
<txp:if_variable name="modified" value='<txp:posted />'>
	<!-- display nothing -->
<txp:else />
| Modified on <txp:modified /> by <txp:php>echo safe_field("RealName", "txp_users", "name='".safe_field("LastModID", "textpattern", "ID='".$thisarticle['thisid']."'")."'");</txp:php>
</txp:if_variable></p>

As you can see above, there are 2 possibilities. Each one works fine for the same purpose.

comments powered by Disqus