Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

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

demoncleaner
Plugin Author
From: Germany
Registered: 2008-06-29
Posts: 228
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: 228
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: 5,689
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: 228
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: 12,498
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.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

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

etc
Developer
Registered: 2010-11-11
Posts: 5,689
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

#37 2021-05-13 19:22:24

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

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

So article_custom has the ability to take every cf-name as an attribute an test some value against it?
Cool. But it is still not working.

When I use

<xsl:for-each select="h4">

instead of

<xsl:for-each select="h4[string()='{?search_month}']">

I get results. Sorry I do not have enough understanding about what happens in the xsl context to see any mistake – if there is any.

Offline

#38 2021-05-13 19:29:56

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

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

Is your search_month variable set (and sanitized) at this stage?

Offline

#39 2021-05-13 19:31:56

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

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

Yes it is. Its value is “2021-05”. So I guess it should show all my current test events that I put in some dates in May.

Offline

#40 2021-05-13 19:35:16

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

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

Have you added specials="content" attribute to <txp:etc_query />? And what happens if you set

<xsl:for-each select="h4[string()='2021-05']">

Offline

#41 2021-05-13 19:52:07

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

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

I have added specials="content", yes.

Here comes my full code. I changed some variables and parameters a bit but without the [string()='{?search_month}'] bit it works (just no month-sorting then)

<txp:variable name="eventslist">
<txp:article_custom wraptag="article" vorstellungen='%<txp:variable name="search_month" />%' section='<txp::sec n="spielplan"/>'><!-- add attributes as needed -->
<txp:etc_query data='<txp::connector_vorstellungen />' markup="ini">

<h4><txp:variable name="mydate" output value="{datum?}"/></h4>

	<div class="card card-body mb-5">
		<div class="row">
			<div class="col-md-2">
				<txp:if_different><div id='d_{datum?}'>{datum?}</div>
				</txp:if_different>
			</div>
			<div class="col-md-2">
				{zeit?}

			</div>
			<div class="col-md-6">
				<h2><txp:title /> </h2>
				<a href="{link?}" class="btn btn-primary">Tickets</a> ({ort?})
			</div>
		</div>

	</div>


</txp:etc_query>
</txp:article_custom>
</txp:variable>

<txp:etc_query specials="content" 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[string()='{?search_month}']">
		<xsl:sort select="." order="ascending" />
		<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>

And what happens if you set
<xsl:for-each select=“h4[string()=‘2021-05’]”>

No output, sorry.

Last edited by demoncleaner (2021-05-13 19:57:26)

Offline

#42 2021-05-13 20:03:51

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

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

Ah, sorry, my bad. I have forgotten that your dates include days too. Try first

<xsl:for-each select="h4[starts-with(., '2021-05')]">

and then

<xsl:for-each select="h4[starts-with(., '{?search_month}')]">

if it works. Here is a list of XPath functions you can use in etc_query.

Offline

#43 2021-05-13 20:08:04

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

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

I was nasty and tried first

<xsl:for-each select="h4[starts-with(., '{?search_month}')]">

=P It works like a charm!!! (the other one as well)

Offline

#44 2021-05-13 20:14:14

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

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

That’s great. Strange that your if_variable attempt produced duplicates (if I get it right), but Ende gut – alles gut!

Offline

#45 2021-05-13 20:23:45

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

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

Ende gut – alles gut!

Ganz genau! =)

I hope that was the biggest task of my project. I am so glad it works now.
Thanks again for your time and help.

Offline

Board footer

Powered by FluxBB