Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-11-01 22:53:54

fhd
Member
Registered: 2009-11-01
Posts: 13

How to add a "Page last updated at..." info?

Hi,

I’m creating a rather static page, with only one or two pages actually containing articles in that sense. The others do only have a single fixed article, as described in the relevant FAQ entry.

Now at the bottom of each page, I’d like to display the date on which this particular page has been changed the last time.

Since a page corresponds to a section in my setup, I think I’ll have to get the modification date of the newest article in the current section, or something similar. However, I wasn’t able to figure it out on my own.

Can someone tell me how to do this?

Offline

#2 2009-11-01 23:13:35

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,502
Website GitHub

Re: How to add a "Page last updated at..." info?

fhd wrote:

I’d like to display the date on which this particular page has been changed the last time.

Does this get you some of the way towards a solution:

Last update: <txp:article_custom section='<txp:section />' limit="1" sort="LastMod desc">
   <txp:modified />
</txp:article_custom>

There might be a more efficient way to do it, as this is just off the top of my head. Hope it helps.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Online

#3 2009-11-01 23:29:17

amordecosmos
Plugin Author
From: London (Hometown: Vancouver)
Registered: 2004-08-03
Posts: 121
Website

Re: How to add a "Page last updated at..." info?

I don’t know if this is more efficient, but this is how I approached it:

On your page where you want the “Last updated” message printed:

<txp:article_custom section="<txp:section />" form="updated" limit="1" />

And in the form named “updated”

Last updated: <txp:posted />

Offline

#4 2009-11-02 07:56:41

fhd
Member
Registered: 2009-11-01
Posts: 13

Re: How to add a "Page last updated at..." info?

Thank you both for the replies. I decided to use Bloke’s way since it wouldn’t require me to create another form.
It does work like a charm after adding status="sticky", which is what I do for my static pages.

Now I just need to have a custom date format, since I’m using it both for the “Last updated” and for a copyright notice (only the year).

But I believe I’ve seen that one on the FAQs, so it should be possible :)

Offline

#5 2009-11-02 08:38:50

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

Re: How to add a "Page last updated at..." info?

Hi fhd

You could probably use amordecosmos solution without a form by using the tag as a container one.

<txp:article_custom section="<txp:section />" limit="1">Last updated: <txp:posted /></txp:article_custom>


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#6 2009-11-02 09:09:46

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,502
Website GitHub

Re: How to add a "Page last updated at..." info?

colak & amordecosmos

Sure thing, both your solutions will work if fhd wants the posted date of the last article. I may have misinterpreted “I think I’ll have to get the modification date of the newest article” by using LastMod and <txp:modified /> in my version. By all means drop them if dealing with posted dates.

fhd wrote:

Now I just need to have a custom date format

Both posted and modified tags take the format argument which allows you to alter the tag’s displayed date format, e.g. format="%Y" for just the year. If you are using this technique for copyright information, sed_copyright is an excellent plugin alternative as it handles all this automatically and does more besides.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Online

#7 2009-11-02 12:47:53

fhd
Member
Registered: 2009-11-01
Posts: 13

Re: How to add a "Page last updated at..." info?

Bloke wrote:

Sure thing, both your solutions will work if fhd wants the posted date of the last article. I may have misinterpreted “I think I’ll have to get the modification date of the newest article” by using LastMod and <txp:modified /> in my version. By all means drop them if dealing with posted dates.

You did get it right, I was looking for the newest modification date on the respective page and it works as expected.
My final solution (which does exactly what I want) is:

<txp:sed_copyright owner="Me meself"/>
&nbsp;|&nbsp;
<txp:article_custom section='<txp:section />' limit="1" sort="LastMod desc">
    Last updated: <txp:modified format="%Y-%m-%d"/>
</txp:article_custom>

Thank you all very much for the kind help!

Offline

#8 2009-11-02 13:11:20

Gallex
Member
Registered: 2006-10-08
Posts: 1,331

Re: How to add a "Page last updated at..." info?

is there a solution if i want to show for visitors when the whole site was last updated?

Offline

#9 2009-11-02 13:12:45

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,502
Website GitHub

Re: How to add a "Page last updated at..." info?

Gallex wrote:

is there a solution if i want to show for visitors when the whole site was last updated?

Try taking out the section='<txp:section />' attribute?


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Online

#10 2009-11-02 14:21:52

Gallex
Member
Registered: 2006-10-08
Posts: 1,331

Re: How to add a "Page last updated at..." info?

Bloke wrote:

Try taking out the section='<txp:section />' attribute?

logged out, waited, refreshed page – it’s displaying my current time. hmm…
my code Last updated: <txp:posted section='<txp:section />' />

Offline

#11 2009-11-02 14:27:32

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,502
Website GitHub

Re: How to add a "Page last updated at..." info?

Gallex wrote:

my code Last updated: <txp:posted section='<txp:section />' />

Why would you do that? <txp:posted /> doesn’t even have a section attribute! :-s

You should try removing the section attribute from the code that fhd posted because you want the article_custom tag to return the most recently modified article from all sections. That’s what you asked, right? Without the section attribute, it returns all articles from all sections by default.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Online

#12 2009-11-02 15:37:43

amordecosmos
Plugin Author
From: London (Hometown: Vancouver)
Registered: 2004-08-03
Posts: 121
Website

Re: How to add a "Page last updated at..." info?

This can be done without a form? <txp:jaw_drops />

Man, I missed a memo somewhere.

Offline

#13 2009-11-02 22:34:53

fhd
Member
Registered: 2009-11-01
Posts: 13

Re: How to add a "Page last updated at..." info?

Hm. I’m still having one problem.

I’ve altered the section list I use for navigation in order to include the default section:

<txp:section_list active_class="selected" break="&nbsp;|&nbsp;" default_title="Home" include_default="1" sections="about, projects, blog" />

And I’ve created a section home whose articles I’ve marked for inclusion on the front page.

Works well so far, except that the following does apparently not iterate over articles included on the default page:

<txp:article_custom section='<txp:section />' limit="1" sort="LastMod desc">
    Last updated: <txp:modified format="%Y-%m-%d"/>
</txp:article_custom>

The dates do not show up, as if there were no articles in the current section (which is kind of true, since they are merely included).

Ideas?

Offline

#14 2009-11-02 22:43:03

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,502
Website GitHub

Re: How to add a "Page last updated at..." info?

fhd wrote:

does apparently not iterate over articles included on the default page:

Hmm yeah, since the article_custom is being limited to ‘this section’ and the default section doesn’t have a notion of ‘this section’ (it’s essentially a section-without-a-portfolio, i.e. "") the article custom probably won’t iterate it.

As a random stab in the dark, you could try this as your section attribute:

section=', <txp:section />'

The initial comma should grab articles from the default section too. (EDIT: you could also try section='default, <txp:section />')

Of course, whether this is desired behaviour on other pages remains to be seen. You may have to do an explicit check for “are we on the front page” (<txp:if_section name="">?) and do a separate article_custom call in both branches :-( Unless someone has any better ideas.

Last edited by Bloke (2009-11-02 22:45:11)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Online

#15 2009-11-03 06:23:44

fhd
Member
Registered: 2009-11-01
Posts: 13

Re: How to add a "Page last updated at..." info?

Bloke wrote:

You may have to do an explicit check for “are we on the front page” (<txp:if_section name=”“>?) and do a separate article_custom call in both branches :-( Unless someone has any better ideas.

I was starting to fear I’d need something like this. At least I’ve found a way where I do not have to duplicate the custom_article:

<txp:article_custom section='<txp:if_section name="default">home<txp:else/><txp:section/></txp:if_section>' limit="1" sort="LastMod desc" status="sticky">
	Last updated: <txp:modified format="%Y-%m-%d"/>
</txp:article_custom>

I’m not totally happy with this solution since I regard it as rather non-elegant, but it pretty much does what I want. Still searching for a way to easily “include” other pages in a layout, this way I’d at least not have to copy that footer to every page layout :)

Offline

Board footer

Powered by FluxBB