Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#25 2021-05-13 13:02:18

etc
Developer
Registered: 2010-11-11
Posts: 4,313
Website GitHub

Re: Sort articles based on multiple dates defined in one custom_field

demoncleaner wrote #330142:

In my specific case I would need to handle multiple events at a day, yes.

That is not a problem, save (a little) for user convenience. You could structure your cf as (say)

[1]
date=2021-05-13
time=18:00
venue=Bolshoi Theatre
[2]
date=2021-05-13
time=21:00
venue=Bolshoi Theatre
...

The only requirement is the [key] uniqueness, up to you to choose it.

Offline

#26 2021-05-13 13:35:08

demoncleaner
Plugin Author
From: Germany
Registered: 2008-06-29
Posts: 168
Website

Re: Sort articles based on multiple dates defined in one custom_field

Sorry I am confused. So at the end it can work with multiple events a day? Like in your syntax above?
But you wrote:

sorry, I must release the ini-version first

So it cannot work, yet?
I tried

<txp:etc_query markup="ini" data="[Day 05]
title=Title of event A
link=https://www.ticketseller.com/12345
[Day 08]
title=Title of event B
link=https://www.ticketseller.com/67890">
    <h4>{#}</h4><!-- date -->
    <a href="{link?}">{title?}</a>
</txp:etc_query>

But I don´t get any ouput apart from a 0.
Maybe I am doing a major mistake here but I am barely understanding the concept and I am not sure if it is supposed to work or not.

Offline

#27 2021-05-13 13:41:51

etc
Developer
Registered: 2010-11-11
Posts: 4,313
Website GitHub

Re: Sort articles based on multiple dates defined in one custom_field

I have just uploaded the ini version, please try again. Otherwise, you can store data in some <txp:variable name="events" /> and call

<txp:etc_query data="{?events||parse_ini_string.json_encode}" markup="json">...

Yes, you can work with multiple events. The main question is what format is acceptable for your client.

Offline

#28 2021-05-13 14:03:56

demoncleaner
Plugin Author
From: Germany
Registered: 2008-06-29
Posts: 168
Website

Re: Sort articles based on multiple dates defined in one custom_field

Yes it works and it looks very promising.
Just cannot figure out now how to sort it by date.

My cf looks like this:

[1]
date=2021-05-13
time=18:00
venue=Bolshoi Theatre
link=https://www.ticketlink.com/456
[2]
date=2021-05-26
time=21:00
venue=OtherTheater
link=https://www.ticketlink.com/1234

Another article might have

[1]
date=2021-05-14
time=18:00
venue=Bolshoi Theatre
link=https://www.ticketlink.com/xxx
[2]
date=2021-05-25
time=21:00
venue=OtherTheater
link=https://www.ticketlink.com/yyy

Output works all fine. Just not ordered by the date.

How can I achieve the desired order now mentioned at the beginning of this thread?
Do I have to use the “xsl stuff” of your example (<xsl:sort select="." order="descending" />) to get the ordering done?

Offline

#29 2021-05-13 14:20:09

etc
Developer
Registered: 2010-11-11
Posts: 4,313
Website GitHub

Re: Sort articles based on multiple dates defined in one custom_field

Great! Yes, you must check first that xsl extension is enabled on your PHP server. Then you would loop over articles and structure the output, say:

<txp:variable name="eventslist">
<txp:article_custom wraptag="article"><!-- add attributes as needed -->
<txp:etc_query data='<txp:custom_field name="events" />' markup="ini">
<h4>{date?}</h4>
<div><a href="{link?}"><txp:title /></a> ({time?}, {venue?})</div>
</txp:etc_query>
</txp:article_custom>
</txp:variable>

Then you pass this variable to etc_query again, to sort and output events:

<txp:etc_query data='<txp:variable name="eventslist" />'>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:txp="https://www.textpattern.com">
<xsl:output method="html" encoding="utf-8" omit-xml-declaration="yes" />
<xsl:template match="article">
	<xsl:for-each select="h4">
		<xsl:sort select="." order="descending" />
		<txp:if_different><xsl:copy-of select="." /></txp:if_different>
		<xsl:copy-of select="following-sibling::div[1]" />
	</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
</txp:etc_query>

I have not tested it, but this should work.

Edit: splitting by [n] is a bit cumbersome, but you can replace them with something more human-readable, like ---. This would require some extra work, but is doable.

Offline

#30 2021-05-13 14:25:55

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,358
Website GitHub

Re: Sort articles based on multiple dates defined in one custom_field

That’s really sweet. Love it.

Very soon we won’t need a CMS. It’ll just be Apache + etc_query :)


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

#31 2021-05-13 14:27:58

demoncleaner
Plugin Author
From: Germany
Registered: 2008-06-29
Posts: 168
Website

Re: Sort articles based on multiple dates defined in one custom_field

Yep! Tested it. It works like it should.
Big “Thank you” to you both!

Offline

#32 2021-05-13 15:51:34

demoncleaner
Plugin Author
From: Germany
Registered: 2008-06-29
Posts: 168
Website

Re: Sort articles based on multiple dates defined in one custom_field

Just to let you know that I am still on it to make it work perfectly.
Because we do not use smd_calendar now anymore unfortunately I need to find another way on how to just display the events of the current month per page. And be able to list other months through a GET variable.

This was already working with my smd_calendar setup.

I try now to check the month from inside the cf inside the etc_query

<txp:variable name="mydate" value="{date?}"/>
<txp:if_variable name="mydate" value='<txp:variable name="search_month"/>' match="any">
...

<txp:variable name="search_month"/> will be current month (2021-05) if no GET parameter was found.

This is almost working. I get some duplicate entries and will need to find out why. But I also ask myself if this is best practice or if it maybe slows things down and if there is a better way.

Last edited by demoncleaner (2021-05-13 15:52:34)

Offline

#33 2021-05-13 17:43:30

etc
Developer
Registered: 2010-11-11
Posts: 4,313
Website GitHub

Re: Sort articles based on multiple dates defined in one custom_field

demoncleaner wrote #330151:

I need to find another way on how to just display the events of the current month per page.

You should be able to pre-filter article_custom and then filter within XSL block:

<txp:variable name="eventslist">
<txp:article_custom events='%<txp:variable name="search_month" />%' wraptag="article">
...
</txp:variable>
<txp:etc_query specials="content"
....
	<xsl:for-each select="h4[string()='{?search_month}']">

And be able to list other months through a GET variable.

Not sure to understand you here.

Offline

#34 2021-05-13 18:36:33

demoncleaner
Plugin Author
From: Germany
Registered: 2008-06-29
Posts: 168
Website

Re: Sort articles based on multiple dates defined in one custom_field

<txp:variable name="eventslist">
<txp:article_custom events='%<txp:variable name="search_month" />%' wraptag="article">
...
</txp:variable>
<txp:etc_query specials="content"
....
	<xsl:for-each select="h4[string()='{?search_month}']">

Whats that “events” attribute in the article_custom? Is that a regular attribute? I tried it out but it is not working.
Just added the events attribute and changed the xsl:for-each line to yours. I get no output anymore.

And be able to list other months through a GET variable.

Don´t worry. Thats not so important. It was just to explain what I am trying to do.
I will be calling my schedule through a URL /schedule/ and it will open the current month.
And I also will call it with /schedule/?search_month=2021-06 for example to display the next month.

Offline

#35 2021-05-13 18:52:34

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,358
Website GitHub

Re: Sort articles based on multiple dates defined in one custom_field

Try swapping events= for the name of your custom field that holds the dates (assuming it doesn’t have a space in its name).

Last edited by Bloke (2021-05-13 18:52:55)


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

#36 2021-05-13 19:20:47

etc
Developer
Registered: 2010-11-11
Posts: 4,313
Website GitHub

Re: Sort articles based on multiple dates defined in one custom_field

Don’t hesitate to post your full code here, it would be easier to debug.

Offline

Board footer

Powered by FluxBB