Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
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
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…
Offline
Re: articles limited by time since posting
will give it a whirl, thanks
Offline
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
Re: articles limited by time since posting
Blimey, that’s dirty.
I like it.
Offline
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
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)
Offline
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
Re: articles limited by time since posting
much obliged gents – it works like a charm
Offline