Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2017-12-26 09:41:38

jpdupont
Member
Registered: 2004-10-01
Posts: 752

Sort problem on Expires, last 4.7 dev

For 6 sections in my site, I want to sort my articles on the expiration date (Expires).
I chose in the settings “Show expired items”.

Expiration dates can therefore be expired for a past event, or not expired for a future event.

I want to display two groups of events:
- Upcoming events with the closest to the top of the list
- Events completed with the newest at the top of the list.

My code below works if I give a limit encompassing all articles like limit="999" :

<h3>Upcoming events</h3>
<txp:article_custom limit="999" section='spectacles' sort="Expires ASC">
        <txp:if_expired>
            <txp:else/>
            <txp:title /><br/>
        </txp:if_expired>
</txp:article_custom>
<h3>Events completed<h3>
<txp:article_custom limit="999" section='spectacles' sort="Expires DESC">
        <txp:if_expired>
            <txp:title /><br/>
        </txp:if_expired>
</txp:article_custom>

But if I want to display only the first of each list (limit= "1"), I get nothing. Do you see an error in this code? I thought that limit to 1 gave me the first item that met the sorting requirement.

Offline

#2 2017-12-26 10:36:32

jpdupont
Member
Registered: 2004-10-01
Posts: 752

Re: Sort problem on Expires, last 4.7 dev

select Title, UNIX_TIMESTAMP(Expires) AS DATE from rox_textpattern WHERE Expires >= CURRENT_DATE() ORDER BY DATE ASC LIMIT 1

select Title, UNIX_TIMESTAMP(Expires) AS DATE from rox_textpattern WHERE Expires < CURRENT_DATE() ORDER BY DATE DESC LIMIT 1

Works as expected …

Offline

#3 2017-12-26 11:00:24

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,726
Website

Re: Sort problem on Expires, last 4.7 dev

I think it‘s because your if_expired tags are excluding the 1 match.

What if you use expired="future" and expired="past" in your article_custom tags as Oleg showed us here?


TXP Builders – finely-crafted code, design and txp

Offline

#4 2017-12-26 14:28:03

jpdupont
Member
Registered: 2004-10-01
Posts: 752

Re: Sort problem on Expires, last 4.7 dev

Thanks Jakob (and Oleg),

Works fine with expired="future" and expired="past".

I had previously searched the code for the new parameters to expired, without finding them …

Offline

Board footer

Powered by FluxBB