Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2023-02-01 17:20:58

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

Listing future articles _and_ those that expired in the last 30 days?

I have a site that shows a series of seminars and workshops where the start date is txp_posted and the end date is txp_expired. Using the time="future" and time="past" plus published expired = yes in the settings, it works well to show upcoming and past events.

Now the client has asked if recently finished events could remain visible in the “upcoming events” for a month before disappearing (simulating if you will the inattentive webmaster).

I can do a time="-30 days" article_custom followed by a time="future article_custom and wrap them in a txp:evaluate to test for the “no current events” case. Or I could extract the article ids for each case and then output those strung together via a third article_custom with a txp:else for the no results case. But is there a succinct way of doing this in one tag?


TXP Builders – finely-crafted code, design and txp

Offline

#2 2023-02-01 18:18:27

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

Re: Listing future articles _and_ those that expired in the last 30 days?

You can try

<txp:article time="since" month="-1month" />

Offline

#3 2023-02-01 20:39:14

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

Re: Listing future articles _and_ those that expired in the last 30 days?

Super-fantastic! That worked! (but you knew it would :-)

And super-simple, too. Another nice new trick you’ve let us in on!


TXP Builders – finely-crafted code, design and txp

Offline

#4 2023-02-02 07:00:35

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,638
GitHub Twitter

Re: Listing future articles _and_ those that expired in the last 30 days?

Perfect. Simple and efficient!

@etc: I have a kind of the same situation for a project: I need to compare an expired date with the current date.

The only solution I found is the following (poor):

<txp:evaluate query='<txp:posted format="%s" /> > ''<txp:php>echo time();</txp:php>'''> ... </txp:evaluate>

Is there a better way to achieve this?


Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

#5 2023-02-02 08:59:33

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

Re: Listing future articles _and_ those that expired in the last 30 days?

@Pat64 you mean, whether posted date is in the future? It looks like this can be achieved with

<txp:if_expired not date="posted">...</txp:if_expired>

Offline

#6 2023-02-02 09:06:42

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,638
GitHub Twitter

Re: Listing future articles _and_ those that expired in the last 30 days?

… I got 1 (true) as a result and not the content I want to display (after the condition)…

Last edited by Pat64 (2023-02-02 09:08:10)


Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

#7 2023-02-02 09:18:49

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

Re: Listing future articles _and_ those that expired in the last 30 days?

Pat64 wrote #334609:

… I got 1 (true) as a result and not the content I want to display (after the condition)…

You have probably closed the tag: <txp:if_expired not date="posted" />? If not, try

<txp:if_expired date="posted"><txp:else />
...
</txp:if_expired>

Offline

#8 2023-02-02 09:32:48

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,638
GitHub Twitter

Re: Listing future articles _and_ those that expired in the last 30 days?

… That’s exactly what I do:

<txp:if_expired not date="posted"><txp:else /><!--googleoff: all--> <p data-nosnippet class="full table m0 txt-c"><span class="full inline-block m0 txt-c">Actuellement : remise de <txp:variable name="discount" escape="number" />&#160;% sur tous les livres brochés <br />appliquée directement dans votre panier d’achats.</span></p> <!--googleon: all--></txp:if_expired>

Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

#9 2023-02-02 09:56:44

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

Re: Listing future articles _and_ those that expired in the last 30 days?

That’s what I get on the demo site:

Actuellement : remise de 0 % sur tous les livres brochés
appliquée directement dans votre panier d’achats.

Offline

#10 2023-02-02 10:58:27

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,638
GitHub Twitter

Re: Listing future articles _and_ those that expired in the last 30 days?

Oops. My bad. You’re right.

Because I need to test future articles, the good code is this one:

<txp:if_expired not date="posted"><!--googleoff: all--> <p data-nosnippet class="full table m0 txt-c"><span class="full inline-block m0 txt-c">Actuellement : remise de <txp:variable name="discount" escape="number" />&#160;% sur tous les livres brochés <br />appliquée directement dans votre panier d’achats.</span></p> <!--googleon: all--><txp:else /></txp:if_expired>

… But, I get better results with the initial construction in article list and/or individual article context.


Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

#11 2023-02-13 10:36:51

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,638
GitHub Twitter

Re: Listing future articles _and_ those that expired in the last 30 days?

Never Mind @etc.
You save my day with this:

<txp:article_custom section="my-main-section" time="future" day="+5day"> Hurry Up! Some info to display </txp:article_custom>

👌


Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

Board footer

Powered by FluxBB