Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2017-12-11 09:52:42

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

How to properly use expired, expires, if_expired ...

I am trying to set up an agenda by using the expiration date of an article as the date on which the article should disappear from the calendar. In the code below, I have to put a limit = "999" to go around all the articles.
Is there a more elegant way to use? If I have 50 items with expiration date, and I want to display the top 10, I can not rely on limit. Apart from putting a counter plugin, I do not see how.

<txp:article_custom wraptag="dl" limit="999" sort="Expires asc">
<txp:if_expires>
<txp:if_expired>
<txp:else/>
<dt><txp:permlink><txp:title /></txp:permlink></dt>
<dd><txp:smd_wrap_all transform="textile"><txp:custom_field name="TexteDateLong" /></txp:smd_wrap_all></dd>
<dd>
<txp:smd_wrap_all transform="strip_tags, cut|200|20w|&hellip;">
<txp:body/>
</txp:smd_wrap_all>&nbsp;<txp:permlink><span>Lire la suite</span></txp:permlink></dd>
</txp:if_expired>
</txp:if_expires>
</txp:article_custom>

Offline

#2 2017-12-11 10:06:56

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

Re: How to properly use expired, expires, if_expired ...

When I do this, I almost always used custom fields to be able to keep event start and end dates separate from the publish date, but I think you can also do it using the posted date as the start date and the expired date as the end date if you specify that article_custom should publish articles in the future and not publish expired articles:

<txp:article_custom section="events" time="any" expired="0" limit="10" sort="Posted desc">
  …
</txp:article_custom>

I think you don’t then need the if_expired or if_expires tags. For this to work, you do need to set the expired date in every event article.

As far as I recall, the fly in the ointment with this method is that the article disappears from the event list on the end date, rather than the day after the end date. To get around that, you also need to set the expired time to the very end of the (working) day.

PS: You might also be able to dispense with the custom field TexteDateLong by using the format="" attribute of txp:posted / txp:expired and strftime values, e.g.

<txp:posted format="%A, %e %B %Y" />

should give you Monday, 11 December 2017 for today’s date. If you set your language locale correctly, it should show you that in your language.


TXP Builders – finely-crafted code, design and txp

Offline

#3 2017-12-11 10:28:28

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

Re: How to properly use expired, expires, if_expired ...

Thank you Jakob, the method you explain is the one I have often used. Especially in version 1 of this site. But I try to listen to customers who are often confused, with too much date field for an article.

If an expired date field exists, why not use it, then?

I do not want to use an “events” section, but directly a section related to the type of events: conferences, shows, concerts, trainings, … So my search for the agenda is done in almost all the sections, for items with expiry assigned, and expiration date not passed. When the expiration date is not assigned, I do not display anything in the calendar. When the expiration date is future (put the day after the event), I list in the agenda. Then the article is automatically placed (archived) in its section initially assigned. It should greatly simplify the work of the client / editor.

BTW, I use a custom field to show the date of the event. The custom field (textarea) is also more flexible for the customer to enter the date of the event, because it can add for example modalities more complex than just date and time. Two performances the same day for example, or the same WE

Last edited by jpdupont (2017-12-11 10:33:41)

Offline

#4 2017-12-11 10:47:16

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

Re: How to properly use expired, expires, if_expired ...

jpdupont wrote #308229:

I do not want to use an “events” section, but directly a section related to the type of events: conferences, shows, concerts, trainings, … So my search for the agenda is done in almost all the sections, for items with expiry assigned, and expiration date not passed. When the expiration date is not assigned, I do not display anything in the calendar. When the expiration date is future (put the day after the event), I list in the agenda. Then the article is automatically placed (archived) in its section initially assigned. It should greatly simplify the work of the client / editor.

One way, if you’re willing to give up if_expires as your criteria for being an event for the calendar would be to use section="conferences,shows,concerts,trainings".

If you have to do it like you suggested, then you could do it in two stages:

<!-- first get long-enough candidate list and store as comma-separated ids in variable -->
<txp:variable name="upcoming-events-ids"><txp:article_custom break="," limit="999" sort="Expires asc"><txp:if_expires><txp:if_expired><txp:else /><txp:article_id /></txp:if_expired></txp:if_expires></txp:article_custom></txp:variable>
<!-- now output shortlist from candidates -->
<txp:article custom id='<txp:variable name="upcoming-events-ids" />' limit="5" wraptag="dl">
  …
</txp:article_custom>

It costs an extra query but should give you what you need…

With smd_query or etc_query you can probably also devise a clever one-query solution.


TXP Builders – finely-crafted code, design and txp

Offline

#5 2017-12-11 10:55:34

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

Re: How to properly use expired, expires, if_expired ...

Thanks Jakob !

Offline

#6 2017-12-11 11:35:35

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

Re: How to properly use expired, expires, if_expired ...

In 4.7-dev, try

<txp:article_custom expired="future" />

Edit: and <txp:custom_field name="TexteDateLong" escape="textile" /> in place of

<txp:smd_wrap_all transform="textile"><txp:custom_field name="TexteDateLong" /></txp:smd_wrap_all>

Offline

#7 2017-12-11 13:15:54

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

Re: How to properly use expired, expires, if_expired ...

<txp:article_custom wraptag="dl" limit="10" expired="future" sort="Expires asc">
<dt><txp:permlink><txp:title /></txp:permlink></dt>
<dd><txp:custom_field name="TexteDateLong" escape="textile" /></dd>
<dd><txp:smd_wrap_all transform="strip_tags, cut|200|20w|&hellip;">
<txp:body/>
</txp:smd_wrap_all>&nbsp;<txp:permlink><span>Lire la suite</span></txp:permlink></dd>
</txp:article_custom>

Oleg, your code is wonderfully simple!
I hope there will be a publication detailing all the improvements of Textpattern v 4.7!
Thanks to you and all the developers for this fantastic job!

Offline

#8 2017-12-11 13:34:18

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,273
Website GitHub

Re: How to properly use expired, expires, if_expired ...

jpdupont wrote #308254:

I hope there will be a publication detailing all the improvements of Textpattern v 4.7!

There’ll be blog posts and docs produced, yes. We’ll write all this when the beta hits so people know what to expect.

One of the things I didn’t tell Oleg when he joined the team was that a condition of his making the tags awesome was that he had to document them too ?

Shhhh….


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#9 2017-12-11 14:12:43

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

Re: How to properly use expired, expires, if_expired ...

The tag documentation is now very clear and well documented! An idea: a “new” or “modified” color label next to each modified or improved tag/attribute in the new version!

Offline

#10 2017-12-11 14:42:01

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,273
Website GitHub

Re: How to properly use expired, expires, if_expired ...

jpdupont wrote #308256:

a “new” or “modified” color label next to each modified or improved tag/attribute in the new version!

You mean like the version indicators we added? Example on the author tag. Also, the tag list shows deprecated tags so it shouldn’t be hard to add a version marker for new tags.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#11 2017-12-11 15:04:02

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: How to properly use expired, expires, if_expired ...

Bloke wrote #308257:

…so it shouldn’t be hard to add a version marker for new tags.

Yes, I can do that when the time is right and the docs are written.

Offline

#12 2017-12-11 15:30:44

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

Re: How to properly use expired, expires, if_expired ...

Yes, like deprecated! I find it more interesting to place a label at the first level of the list of tags, reserving the label “new” or “upgraded” when switching from one version to another. In the next version (4.8, …), what was new before is no longer and these labels are reserved for the latest improvements of the tool.

Offline

Board footer

Powered by FluxBB