Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2020-06-20 13:57:53

gaekwad
Admin
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 2,989

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 is bar.
  • foo might be category1, it might be category2, and the same goes for bar.
  • Only articles with both categories set (i.e. foo AND bar, not foo 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

#2 2020-06-20 15:15:26

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,003
Website

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 is bar.
  • foo might be category1, it might be category2, and the same goes for bar.
  • Only articles with both categories set (i.e. foo AND bar, not foo 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.org | hblack.net | LABS | State Machines | NeMe @ github | Covid-19; a resource
I do my best editing after I click on the submit button.

Offline

#3 2020-06-20 15:22:53

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,003
Website

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.org | hblack.net | LABS | State Machines | NeMe @ github | Covid-19; a resource
I do my best editing after I click on the submit button.

Offline

#4 2020-06-20 15:24:14

gaekwad
Admin
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 2,989

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

#5 2020-06-20 15:24:50

gaekwad
Admin
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 2,989

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

#6 2020-06-20 15:28:37

Dragondz
Moderator
From: Algérie
Registered: 2005-06-12
Posts: 1,355
Website

Re: Some article_custom kung fu - articles with both of 2 categories

Hi Pete

You could use smd_query

I dont know if it s possible with native txp tag

Cheers.

Offline

#7 2020-06-20 15:33:09

gaekwad
Admin
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 2,989

Re: Some article_custom kung fu - articles with both of 2 categories

Dragondz wrote #323863:

You could use smd_query

Thanks, Rabah – I will investigate!

Offline

#8 2020-06-20 16:00:37

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,003
Website

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.org | hblack.net | LABS | State Machines | NeMe @ github | Covid-19; a resource
I do my best editing after I click on the submit button.

Offline

#9 2020-06-20 16:42:46

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,003
Website

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.org | hblack.net | LABS | State Machines | NeMe @ github | Covid-19; a resource
I do my best editing after I click on the submit button.

Offline

#10 2020-06-20 16:51:19

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,469
Website

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

Offline

Board footer

Powered by FluxBB