Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2021-06-23 12:18:14

Kjeld
Member
From: Tokyo, Japan
Registered: 2005-02-05
Posts: 453
Website

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

#2 2021-06-23 13:03:34

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,093
Website GitHub Mastodon Twitter

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

#3 2021-06-23 13:19:07

Kjeld
Member
From: Tokyo, Japan
Registered: 2005-02-05
Posts: 453
Website

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

#4 2021-06-23 13:50:34

etc
Developer
Registered: 2010-11-11
Posts: 5,236
Website GitHub

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

#5 2021-06-23 14:28:20

Kjeld
Member
From: Tokyo, Japan
Registered: 2005-02-05
Posts: 453
Website

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

#6 2021-06-23 17:47:11

etc
Developer
Registered: 2010-11-11
Posts: 5,236
Website GitHub

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

#7 2021-06-24 11:55:06

Kjeld
Member
From: Tokyo, Japan
Registered: 2005-02-05
Posts: 453
Website

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 or archive_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

#8 2022-04-09 04:48:50

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,093
Website GitHub Mastodon Twitter

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

#9 2022-04-09 06:17:12

Kjeld
Member
From: Tokyo, Japan
Registered: 2005-02-05
Posts: 453
Website

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

#10 2022-04-09 15:55:54

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,093
Website GitHub Mastodon Twitter

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

#11 2022-04-11 10:23:36

Kjeld
Member
From: Tokyo, Japan
Registered: 2005-02-05
Posts: 453
Website

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

Board footer

Powered by FluxBB