Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
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
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
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
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
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
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
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
Re: Sort articles based on multiple dates defined in one custom_field
Is your search_month variable set (and sanitized) at this stage?
Offline
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
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
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
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
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
Offline
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