Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
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
Re: Listing future articles _and_ those that expired in the last 30 days?
You can try
<txp:article time="since" month="-1month" />
Offline
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
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
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
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
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
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" /> % 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
Offline
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" /> % 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
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