Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-07-24 11:27:16

pieman
Member
From: Bristol, UK
Registered: 2005-09-22
Posts: 491
Website

articles limited by time since posting

I’ve always used chh_article_custom with time="-1 year" to limit to articles posted in the last 12 months. It still works, but that plugin is getting on a bit now and throws Tag errors in Testing mode.

Are there any other newer, lighter or generally better alternatives?

Offline

#2 2009-07-24 14:09:49

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: articles limited by time since posting

Hi pieman,

while still thinking if this could be done using txp built in tags (I doubt it, but then it comes a genius and proves me wrong), I think it could be done using smd_calendar (particularly, using the smd_article_event tag and playing with from, to and/or offset attributes) but it may be a little overkiller…


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#3 2009-07-24 14:19:09

pieman
Member
From: Bristol, UK
Registered: 2005-09-22
Posts: 491
Website

Re: articles limited by time since posting

will give it a whirl, thanks

Offline

#4 2009-07-24 14:26:12

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,270
Website GitHub

Re: articles limited by time since posting

Or, if you fancy a kludge:

<txp:article_custom section="article" limit="999" wraptag="ul" break="li">
<txp:smd_if field='<txp:posted format="%s" />' operator="ge" value='<txp:php>echo time()-365*24*60*60;</txp:php>'>
  <txp:title /> is within the last year, see: <txp:posted />
</txp:smd_if>
</txp:article_custom>

does what you want, albeit with the grace and beauty of a stoat being kicked down a metal stairwell with a tin can tied to its tail1.

If you have smd_calendar already installed anyway, <txp:smd_cal_now /> is a nicer alternative to that ‘orrible hunk of PHP maths up there.

1 No animals were harmed in the making of this example.

Last edited by Bloke (2009-07-24 14:29:03)


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

Txp Builders – finely-crafted code, design and Txp

Offline

#5 2009-07-24 14:33:25

pieman
Member
From: Bristol, UK
Registered: 2005-09-22
Posts: 491
Website

Re: articles limited by time since posting

Blimey, that’s dirty.

I like it.

Offline

#6 2009-07-27 11:30:01

pieman
Member
From: Bristol, UK
Registered: 2005-09-22
Posts: 491
Website

Re: articles limited by time since posting

I’m struggling with the finer points of smd_cal_now.

To retrieve titles from articles posted within the last 12 months from the given section/cats, I whittled it down to this:

<txp:smd_article_event section="journal" category='<txp:category1 />'
from='<txp:smd_cal_now />'
to='<txp:smd_cal_now now="?day-?month-01" />'
>
<txp:title />
</txp:smd_article_event>

But the lack of output makes me think I’m wide of the mark slightly… am I right in my wrongness?

Offline

#7 2009-07-27 11:39:20

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: articles limited by time since posting

Hi Stu,

have you tried switching the values for from and to? (like from='<txp:smd_cal_now now="?day-?month-01" />' to='<txp:smd_cal_now />')

Last edited by maniqui (2009-07-27 11:39:36)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#8 2009-07-27 11:42:29

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,270
Website GitHub

Re: articles limited by time since posting

pieman wrote:

To retrieve titles from articles posted within the last 12 months from the given section/cats…

I think you’ll need to go the other way round: from is the earliest date and to is ‘now’. Also note that ?day, ?month and ?year are replaced with today’s values. This should do it:

<txp:smd_article_event section="journal" category='<txp:category1 />'
     from='<txp:smd_cal_now offset="-12 months" />' 
     to='<txp:smd_cal_now />'
     >
   <txp:title />
</txp:smd_article_event>

I’ve never tried going ‘back’ using a negative time offset, but I expect it’ll work.

EDIT: maniqui was faster ;-)

Last edited by Bloke (2009-07-27 11:45:23)


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

Txp Builders – finely-crafted code, design and Txp

Offline

#9 2009-07-27 11:48:58

pieman
Member
From: Bristol, UK
Registered: 2005-09-22
Posts: 491
Website

Re: articles limited by time since posting

much obliged gents – it works like a charm

Offline

Board footer

Powered by FluxBB