Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2011-02-04 15:01:41
- beechy
- Member
- Registered: 2006-03-02
- Posts: 92
Display only articles posted in the last two days
Hi all,
How would I display only articles posted in the last two days using –
<txp:article_custom />
I would prefer to not use a plugin if possible.
Thanks for your help
Offline
Re: Display only articles posted in the last two days
The plug-in to check is ras_if_dates.
Without a plug-in you’ll need <txp:php>
to fill in some PHP date calculation yourself.
month=“yyyy”/“yyyy-mm”/“yyyy-mm-dd”
Restrict to articles posted within the specified year/month/day.
You’ll replace month="yyyy-mm-dd"
with month='<txp:php> ... </txp:php>'
(single quotes!)
Check out php.net … function.date.php (see eg example 4).
Disadvantages
- This would also mean to have two
<txp:article_custom />
for the last two days (today + yesterday). - Context-sensitive navigation tags, such as older and newer, will not work
- No
<txp:else />
to catch empty output
Sorry, but date functions/calculations are pretty much absent on business in Textpattern core.
Get all online mentions of Textpattern via OPML subscription: TXP Info Sources: Textpattern RSS feeds as dynamic OPML
Offline
Re: Display only articles posted in the last two days
I cannot think of a native way and don’t know php but there is csb_if_newer_than which might do the job
Untested
<txp:csb_if_newer_than days="2"><txp:article><txp:body /></txp:article></txp:csb_if_newer_than>
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
#4 2011-02-04 18:15:32
- beechy
- Member
- Registered: 2006-03-02
- Posts: 92
Re: Display only articles posted in the last two days
Hi merz1
Thanks for your help….
I have used -
month=’<txp:php>echo date(‘Y-m-d’);</txp:php>’ – for todays date
month=’<txp:php>echo date(“Y-m-d”,mktime(0, 0, 0, date(“m”),date(“d”)-1,date(“Y”)));</txp:php>’ – for yesterdays date
These work fine.
However as you noted there is nothing to catch an empty output, could the ‘if_different’ tag be used for this?
Offline
Re: Display only articles posted in the last two days
I think the easier way is to use <txp:variable> (follow Example 2). There are pretty many use cases in the forum threads.
Edit: if_different
is used for catching changing content in a list (like an extra day flag when posted days switch).
Last edited by merz1 (2011-02-04 18:39:50)
Get all online mentions of Textpattern via OPML subscription: TXP Info Sources: Textpattern RSS feeds as dynamic OPML
Offline