Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Some article_custom kung fu - articles with both of 2 categories
Here’s what I’m trying to do:
- Select articles where the categories are both set, one is
foo
, the other isbar
. foo
might becategory1
, it might becategory2
, and the same goes forbar
.- Only articles with both categories set (i.e.
foo AND bar
, notfoo OR bar
) should be selected.
I’m building out a whacky tag scaffold that checks for the existence of both categories being set first, then does the conditional checks…and it’s a mess. It works, but yuck.
Is there a fancy way with modern Textpattern tooling that I can grok and use? Assume I’ve spent a lot of time fixing Textpatterns recently, and not building them, and you’ll understand my headspace.
Thanking you, and happy weekend.
Offline
Re: Some article_custom kung fu - articles with both of 2 categories
isnt
gaekwad wrote #323858:
Here’s what I’m trying to do:
- Select articles where the categories are both set, one is
foo
, the other isbar
.foo
might becategory1
, it might becategory2
, and the same goes forbar
.- Only articles with both categories set (i.e.
foo AND bar
, notfoo OR bar
) should be selected.
I’m building out a whacky tag scaffold that checks for the existence of both categories being set first, then does the conditional checks…and it’s a mess. It works, but yuck.
Is there a fancy way with modern Textpattern tooling that I can grok and use? Assume I’ve spent a lot of time fixing Textpatterns recently, and not building them, and you’ll understand my headspace.
Thanking you, and happy weekend.
Hi Pete,
Isn’t that how the related_articles tag works? By default it matches category1,category2.
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: Some article_custom kung fu - articles with both of 2 categories
Also… I just tried to test my hypothesis above in the demo site, but I cannot login using the credentials offered, and more strangely, the remember tick-box does not tick. It just gets dark for a second and then returns to white.
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: Some article_custom kung fu - articles with both of 2 categories
colak wrote #323859:
Isn’t that how the related_articles tag works? By default it matches category1,category2.
Thanks, Yiannis – I didn’t explain myself very well. I’m looking for advice on how to select the initial articles, not the subsequent related articles from a single article. As I understand it, related_articles
is what’s used to generate similar articles based on a single article – as you say, based on its categories.
Offline
Re: Some article_custom kung fu - articles with both of 2 categories
colak wrote #323860:
Also… I just tried to test my hypothesis above in the demo site, but I cannot login using the credentials offered, and more strangely, the tick-box does not tick. It just gets dark for a second and then returns to white.
Rats. I must’ve broken it. I’ll investigate – thanks for the heads up.
Edit: yeah, I broke it. Give me ten mins and I’ll fix it. Sorry.
Edit: fixed. Mea culpa.
Last edited by gaekwad (2020-06-20 15:32:10)
Offline
Re: Some article_custom kung fu - articles with both of 2 categories
Offline
Re: Some article_custom kung fu - articles with both of 2 categories
Offline
Re: Some article_custom kung fu - articles with both of 2 categories
gaekwad wrote #323861:
Thanks, Yiannis – I didn’t explain myself very well. I’m looking for advice on how to select the initial articles, not the subsequent related articles from a single article. As I understand it,
related_articles
is what’s used to generate similar articles based on a single article – as you say, based on its categories.
I’m trying to understand. You are looking to generate an article_custom page where the article list shown have the same categories and do not take into consideration the order that those categories were selected. If so, here’s something to get you started:
<txp:variable name="cat1articles"><txp:article_custom section="your_section" break=";" wraptag="" category="cat1" limit="999"><txp:article_id /></txp:article_custom></txp:variable>
<txp:variable name="cat2articles"><txp:article_custom section="your_section" break=";" wraptag="" category="cat2" limit="999"><txp:article_id /></txp:article_custom></txp:variable>
Then it is the part that I’m yet to solve but the idea is that you only include the ids present in both variables, possibly using the evaluate tag(?) and return them with <txp:article_custom id="whatever here" limit="999" />
.
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: Some article_custom kung fu - articles with both of 2 categories
Alternatively there maybe another simpler way:)
<txp:article_custom id="##"><txp:related_articles /></txp:article_custom>
> Edited to say that I tested the above and the default value of the match
attribute in the related_articles
tag is OR
. I’m not sure if there is a way to have
<txp:article_custom id="##"><txp:related_articles match="category1 AND category2" /></txp:article_custom>
Last edited by colak (2020-06-20 16:51:28)
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: Some article_custom kung fu - articles with both of 2 categories
Short of using exclude
or evaluate
in clever ways that only Oleg can usually fathom, the best I can do is this:
<txp:variable name="with-foo" escape="trim">
<txp:article_custom category="foo" break=","><txp:article_id /></txp:article_custom>
</txp:variable>
<txp:article_custom id='<txp:variable name="with-foo" />' category="bar" break="li" wraptag="ul">
<txp:title />
</txp:article_custom>
Cheating, really: make a comma-separated list of ID values in a variable that match the first category, then use that list in a second <txp:article_custom>
that’s told to match the second category.
Not very efficient, and you’ll need some limit="999"
hackery attributes in there to get everything.
Last edited by Bloke (2020-06-20 16:52:33)
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
Online
Re: Some article_custom kung fu - articles with both of 2 categories
Much obliged, sirs – thank you very much. I will report back!
Offline
Re: Some article_custom kung fu - articles with both of 2 categories
I’ve made
<txp:article_custom match="Category1, Category2" category="foo, bar" />
in dev act as Pete asks, i.e. yield both Category1, Category2
be in foo, bar
. This is more consistent with general AND
logic of match
, where categories were an exception. The previous OR
behaviour is obtained with
<txp:article_custom match="Category" category="foo, bar" />
or simply by omitting match
attribute. Dunno whether to merge it into 4.8.2, it’s potentially not bw-compatible, though the risk is tiny.
Offline