Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2013-06-19 22:05:36

Manaus
Member
From: Turin, Italy
Registered: 2010-10-22
Posts: 252
Website

Displaying events expiring in the future

Hello,
I need to display 4 events which will explire in the close future, in ascending order, but I’m having troubles.

Order is:

  • Closest
  • Closer
  • Close

time="future" displays only events whose posting date is in the future. Sort="Expires asc" displays also past events. Sort="Expires desc" limit="4" works good but I need them in reverse order.

Thanks for any suggestion…

Offline

#2 2013-06-19 22:33:29

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Displaying events expiring in the future

Does this work? time="any" sort="expires asc" limit="4" expired="0"

Edit: just noticed that expired is an attribute for article_custom only…

Last edited by els (2013-06-19 22:36:10)

Offline

#3 2013-06-20 07:11:10

Manaus
Member
From: Turin, Italy
Registered: 2010-10-22
Posts: 252
Website

Re: Displaying events expiring in the future

Thanks Els,
Just tried out, this is my code <txp:article_custom form="homenewsmin" limit="4" section="appuntamenti" sort="Expires asc" expired="0" time="any" /> but either with or without expired="0" I get same results (very old posts)…

Edit: Using 4.4.0 on this website, maybe time for an update…

Thanks!

Last edited by Manaus (2013-06-20 07:19:06)

Offline

#4 2013-06-20 08:12:20

springworks
Member
Registered: 2005-01-06
Posts: 172
Website

Re: Displaying events expiring in the future

Manaus wrote:

Hello,
I need to display 4 events which will explire in the close future, in ascending order, but I’m having troubles.

Order is:

  • Closest
  • Closer
  • Close

time="future" displays only events whose posting date is in the future. Sort="Expires asc" displays also past events. Sort="Expires desc" limit="4" works good but I need them in reverse order.

Thanks for any suggestion…

Just thinking off the top of my head here, but if Sort="Expires desc" limit="4" gives you what you need but just in the reverse order, then all you need is to work out a way of reversing the order of that query.

I wonder if it is possible to hack together something using a combination adi_calc and Textpattern variables to do it?

As you know that you only want to display the next 4 articles to expire, you could do something like this (untested) to capture the values in Txp variables, then use the values in these variables to output the results in the order you wanted them:

<txp:hide>Capture articles in Txp variables</txp:hide>

<txp:variable name="article_index" value="4" />

<txp:article_custom section="appuntamenti" sort="Expires desc" limit="4">
  <txp:variable name="article_title_'<txp:variable name="article_index" />'"><txp:permlink><txp:title /></txp:permlink></txp:variable>
  <txp:variable name="article_excerpt_'<txp:variable name="article_index" />'"><txp:excerpt /></txp:variable>
  <txp:variable name="article_body_'<txp:variable name="article_index" />'"><txp:body /></txp:variable>

  <txp:adi_calc name="article_index" subtract="1" />
</txp:article_custom>

<txp:hide>Now display captured articles as desired, e.g. as ordered list of linked titles</txp:hide>

<h2>Articles about to expire</h2>

<ol>
  <li><txp:variable name="article_title_1" /></li>
  <li><txp:variable name="article_title_2" /></li>
  <li><txp:variable name="article_title_3" /></li>
  <li><txp:variable name="article_title_4" /></li>
</ol>

Equally, etc_query or smd_query might be up to the task, but I’m afraid I’m not familiar enough with either of them to come up with how!

Offline

#5 2013-06-20 13:08:25

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

Re: Displaying events expiring in the future

sort="Expires desc" limit="4" will only work if you have less than 5 expiring articles. I can’t see a core solution right now, but you can try plugins (smd_query or etc_query):

<txp:etc_query markup="db" break="," name="near_future"
	data="SELECT ID FROM textpattern WHERE Status=4 AND Expires>NOW() ORDER BY Expires ASC LIMIT 4" />
<txp:article_custom id='<txp:variable name="near_future" />' form="my_form" sort="Expires ASC" />

You can also avoid the second query (<txp:article_custom />), extracting the fields you need (Title, etc) with etc_query.

Offline

#6 2013-06-20 13:14:29

springworks
Member
Registered: 2005-01-06
Posts: 172
Website

Re: Displaying events expiring in the future

Ah, there you go, I knew there had to be a better solution than mine!

Offline

#7 2013-06-20 13:27:31

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

Re: Displaying events expiring in the future

I have never tried it, but aks_article could be an even simpler solution, since it accepts where attribute.

Offline

#8 2013-06-22 15:24:03

Manaus
Member
From: Turin, Italy
Registered: 2010-10-22
Posts: 252
Website

Re: Displaying events expiring in the future

Just wondering, if I get so many answers, that’s because the method exposed by Els in not working for you too. Why is that, since it looks to be semantically right?…

Offline

#9 2013-06-22 15:45:02

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

Re: Displaying events expiring in the future

I guess it displays also the articles without expiration date. If you always have at least four articles with future expiration date, you can try the weird

<txp:article_custom limit="4" sort="IF(`Expires` > NOW(), `Expires`, 2100) ASC" />

Last edited by etc (2013-06-22 16:34:21)

Offline

#10 2013-06-22 17:29:42

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Displaying events expiring in the future

etc wrote:

I guess it displays also the articles without expiration date.

Ah, I was wondering about that too. I’ll keep this in mind for future cases, thanks Oleg!

Offline

Board footer

Powered by FluxBB