Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
How can I only show txp:modified if article is modified?
I only want to show txp:modified if an article is indeed modified. How do I do that?
If I use this, modified is always shown, even when an article has just been listed:
<txp:evaluate test="modified">Updated <txp:modified format="%B %e, %Y %l:%M %p" /></txp:evaluate>
I tried this, but get nothing:
<txp:evaluate query='<txp:posted /> < <txp:modified />'>Updated <txp:modified format="%B %e, %Y %l:%M %p" /></txp:evaluate>
Any suggestions?
• Old Photos of Japan – Japan in the 1850s~1960s (100% txp)
• MeijiShowa – Stock photos of Japan in the 1850s~1960s (100% txp)
• JapaneseStreets.com – Japanese street fashion (mostly txp)
Offline
Re: How can I only show txp:modified if article is modified?
I just tried your code on the txp demo, and this works: <txp:evaluate test="modified">Updated <txp:modified format="%B %e, %Y %l:%M %p" /></txp:evaluate>
.
Alternatively you can try the following in an article context.
<txp:variable name="modified"><txp:modified format="%B %e, %Y %l:%M %p" /></txp:variable>
<txp:if_variable name="modified" value="">
<txp:else />
Updated: <txp:modified format="%B %e, %Y %l:%M %p" />
</txp:if_variable>
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: How can I only show txp:modified if article is modified?
Thank you!
colak wrote #330632:
I just tried your code on the txp demo, and this works:
<txp:evaluate test="modified">Updated <txp:modified format="%B %e, %Y %l:%M %p" /></txp:evaluate>
.
Is the Updated info hidden on new articles or when you reset the timestamp of an article to now? On my site it always shows…
Alternatively you can try the following in an article context.
<txp:variable name="modified"><txp:modified format="%B %e, %Y %l:%M %p" /></txp:variable>...
I tried this too, but it also shows on new articles or when I reset the timestamp of an article to now.
The idea is that Updated only shows when the article has indeed been modified, and is hidden when no modification has been made.
Last edited by Kjeld (2021-06-23 13:19:57)
• Old Photos of Japan – Japan in the 1850s~1960s (100% txp)
• MeijiShowa – Stock photos of Japan in the 1850s~1960s (100% txp)
• JapaneseStreets.com – Japanese street fashion (mostly txp)
Offline
Re: How can I only show txp:modified if article is modified?
Kjeld wrote #330630:
I tried this, but get nothing:
<txp:evaluate query='<txp:posted /> < <txp:modified />'>Updated <txp:modified format="%B %e, %Y %l:%M %p" /></txp:evaluate>...
This should work if you set format="%s"
when comparing dates. Otherwise, I suspect that txp would complain about incorrect expression in debug mode.
For the record, <txp:modified />
seems to be set to the date of posting for unmodified articles.
Offline
Re: How can I only show txp:modified if article is modified?
etc wrote #330634:
This should work if you set
format="%s"
when comparing dates. Otherwise, I suspect that txp would complain about incorrect expression in debug mode.For the record,
<txp:modified />
seems to be set to the date of posting for unmodified articles.
format="%s"
did the trick!
I actually assumed that when nothing was set, the Unix Epoch Time timestamps would be compared. Good to know that you have to specifically set it.
Also, good to know that <txp:modified />
seems to be set to the date of posting for unmodified articles. That explains why the other method could not work…
Thank you very much.
• Old Photos of Japan – Japan in the 1850s~1960s (100% txp)
• MeijiShowa – Stock photos of Japan in the 1850s~1960s (100% txp)
• JapaneseStreets.com – Japanese street fashion (mostly txp)
Offline
Re: How can I only show txp:modified if article is modified?
Kjeld wrote #330635:
format="%s"
did the trick!
Glad it works for you. A (slightly) faster option might be to use <txp:custom_field name="posted|modified" />
for comparison, though it feels a bit hacky.
I actually assumed that when nothing was set, the Unix Epoch Time timestamps would be compared.
It is dateformat
or archive_dateformat
pref, depending on the context.
Offline
Re: How can I only show txp:modified if article is modified?
etc wrote #330636:
Glad it works for you. A (slightly) faster option might be to use
<txp:custom_field name="posted|modified" />
for comparison, though it feels a bit hacky.It is
dateformat
orarchive_dateformat
pref, depending on the context.
Thanks!
• Old Photos of Japan – Japan in the 1850s~1960s (100% txp)
• MeijiShowa – Stock photos of Japan in the 1850s~1960s (100% txp)
• JapaneseStreets.com – Japanese street fashion (mostly txp)
Offline
Re: How can I only show txp:modified if article is modified?
etc wrote #330634:
This should work if you set
format="%s"
when comparing dates. Otherwise, I suspect that txp would complain about incorrect expression in debug mode.For the record,
<txp:modified />
seems to be set to the date of posting for unmodified articles.
I’m coming back to this thread as I have a relevant issue. I am trying to show the posted date unless the article has been modified, for which case I wish to show the modified date. Would this be the correct way of doing it?
<txp:evaluate query='<txp:posted format="%s" /> < <txp:modified format="%s" />'>
<txp:modified format="%B %e, %Y %l:%M %p" />
<txp:else />
<txp:posted format="%B %e, %Y %l:%M %p" />
</txp:evaluate>
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: How can I only show txp:modified if article is modified?
colak wrote #333058:
I’m coming back to this thread as I have a relevant issue. I am trying to show the posted date unless the article has been modified, for which case I wish to show the modified date. Would this be the correct way of doing it?
<txp:evaluate query='<txp:posted format="%s" /> < <txp:modified format="%s" />'>
<txp:modified format="%B %e, %Y %l:%M %p" />
<txp:else />
<txp:posted format="%B %e, %Y %l:%M %p" />
</txp:evaluate>
I just tested this on my site, and it works perfectly.
• Old Photos of Japan – Japan in the 1850s~1960s (100% txp)
• MeijiShowa – Stock photos of Japan in the 1850s~1960s (100% txp)
• JapaneseStreets.com – Japanese street fashion (mostly txp)
Offline
Re: How can I only show txp:modified if article is modified?
Thanks so much for testing Kjeld, it works flawlessly over at my site too.
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: How can I only show txp:modified if article is modified?
colak wrote #333062:
Thanks so much for testing Kjeld, it works flawlessly over at my site too.
Good to hear!
Incidentally, glad that one of my experiments helps somebody else, too!
Last edited by Kjeld (2022-04-11 10:24:15)
• Old Photos of Japan – Japan in the 1850s~1960s (100% txp)
• MeijiShowa – Stock photos of Japan in the 1850s~1960s (100% txp)
• JapaneseStreets.com – Japanese street fashion (mostly txp)
Offline