Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2020-06-17 17:42:32

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 619
Website

Display articles base on date range

Hi, I would like to display articles base on date range, for example 2020-06-01 to 2020-06-10.
From what I see the month attribute is for a single value (day/month/year), is there a syntax also for date range please?

I need to display articles of last week, this week, and next week, is there a simple way of doing that please?

This is what I got so far for getting the dates, but not sure how to use them in the month attribute, or do I need to use PHP for that?

<txp:php>
    global $variable;

    $sundayThisWeek = strtotime('last sunday', strtotime('tomorrow'));
    $saturdayThisWeek = strtotime('+6 days', $sundayThisWeek);

    $sundayLastWeek = strtotime('-7 days', $sundayThisWeek);
    $sundayNextWeek = strtotime('next week sunday', strtotime('tomorrow'));
    $saturdayNextWeek = strtotime('+7 days', $saturdayThisWeek);

    $variable['week_last_start_date'] = date('Y-m-d', $sundayLastWeek);
    $variable['week_this_start_date'] = date('Y-m-d', $sundayThisWeek);
    $variable['week_next_start_date'] = date('Y-m-d', $sundayNextWeek);
    $variable['week_next_end_date'] = date('Y-m-d', $saturdayNextWeek);
</txp:php>

<txp:article_custom section="schedule" form="schedule_item" time="any" expired="1" month='<txp:variable name="week_last_start_date" /> to <txp:variable name="week_next_end_date" />' />

Last edited by THE BLUE DRAGON (2020-06-17 18:11:02)

Offline

#2 2020-06-17 21:34:35

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

Re: Display articles base on date range

Hi, have you tried <txp:article month="2020-06-01" time="+10 days" />?

Offline

#3 2020-06-17 21:56:04

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 619
Website

Re: Display articles base on date range

etc wrote #323818:

Hi, have you tried <txp:article month="2020-06-01" time="+10 days" />?

Cool thanks, how can I also add any to the time attribure together with the +days string? I need to also include future articles please.

Offline

#4 2020-06-17 21:59:10

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

Re: Display articles base on date range

THE BLUE DRAGON wrote #323819:

Cool thanks, how can I also add any to the time attribure together with the +days string? I need to also include future articles please.

IIRC, you don’t have to add any, +10 days should replace it. But I need to check.

Offline

#5 2020-06-17 22:13:49

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 619
Website

Re: Display articles base on date range

etc wrote #323820:

IIRC, you don’t have to add any, +10 days should replace it. But I need to check.

Thanks, yes I forgot to set the limit attribute value to include more.

Offline

Board footer

Powered by FluxBB