Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2013-10-17 09:37:04

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,356
GitHub

[SOLVED] Last updated x days ago

I want to have Last updated: x days ago on my sections. My logic is based around the following: use article_custom to select all articles from the current section, sort by last modified date in descending order (newest first), limit the output to one article and then use an article form to extract the modified data in a since format. I’m using plain text to output the Last updated: part, and a form to get the rest. Like this:

Page code

<txp:article_custom form="article_modified_since" limit="1" section="<txp:section />" sort="LastMod desc" />

Code from article_modified_since

<txp:modified format="since" />

That doesn’t work, and I’m a bit puzzled as to why not: nothing it outputted and there are no errors displayed. Here’s a tag trace:

<txp:article_custom form="article_modified_since" limit="1" section="<txp:section />" sort="LastMod desc" />
[SQL (0.00079202651977539): select *, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod from textpattern where 1=1 and Status = 4 and Posted <= now() and Section IN ('<txp:section />') order by LastMod desc limit 0, 1]

…which doesn’t seem to be a lot of help, I’m afraid.

I’m sure this is something obvious that, sadly, I can’t spot. Any pointers are appreciated. Thank you.

Last edited by gaekwad (2013-10-17 09:44:02)

Offline

#2 2013-10-17 09:42:34

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

Re: [SOLVED] Last updated x days ago

'<txp:section />', Pete.

Offline

#3 2013-10-17 09:43:48

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,356
GitHub

Re: [SOLVED] Last updated x days ago

Aha! Thank you, Oleg – I am grateful for your eyes.

Offline

#4 2013-10-17 10:54:05

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

Re: [SOLVED] Last updated x days ago

You are welcome, as usual. :) Actually, the tag trace was very helpful — you shouldn’t (normally) have txp tags in db queries.

Offline

#5 2013-10-17 12:36:33

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,356
GitHub

Re: [SOLVED] Last updated x days ago

etc wrote:

[…] you shouldn’t (normally) have txp tags in db queries.

This is a tricky situation to avoid, at least from my reasoning.

I was previously using article instead of article_custom, but the section pagination threw off the Last updated: value by returning the most recent article on that page. This is expected behaviour, of course, but I couldn’t figure out of a way of restricting the article_custom query to only check articles from the current section without that section='<txp:section />' attribute.

It works for me as I anticipated, so thank you very much.

Offline

#6 2013-10-17 12:59:18

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

Re: [SOLVED] Last updated x days ago

gaekwad wrote:

I couldn’t figure out of a way of restricting the article_custom query to only check articles from the current section without that section='<txp:section />' attribute.

Sorry for my “english”, section='<txp:section />' is quite ok. I meant, seeing txp tags in

[SQL (0.00079202651977539): select *, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod from textpattern where 1=1 and Status = 4 and Posted <= now() and Section IN ('<txp:section />') order by LastMod desc limit 0, 1]

is suspect, it should be Section IN ('current_section') at this stage.

Offline

#7 2013-10-17 14:05:30

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,356
GitHub

Re: [SOLVED] Last updated x days ago

Hi Oleg. Oh, now I understand – you need not apologise, I know for certain your English is exponentially better than my Russian proficiency!

Offline

Board footer

Powered by FluxBB