Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2025-03-27 20:51:13

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

Re: Filter by multiple categories

The tag compares category (current or specified) against a list of names:

<txp:if_category category="apple" name="apple, banana, cherry" /> <!-- yes! -->

So

<txp:if_category name="apple, banana, cherry" />

checks whether the current category is in the list. But there is no current category on /category/apple/banana/ page, as we know.

Offline

#14 2025-03-27 21:01:09

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,758
Website GitHub

Re: Filter by multiple categories

Ah of course. That could probably be clearer in the docs.

*adds it to the never-ending Todo list*


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

#15 2025-05-22 15:56:48

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,758
Website GitHub

Re: Filter by multiple categories

Just revisiting this one with a tweak. From articles such as /section/title/some-cat, I’m extracting <page::url type="3"> (some-cat) into a variable (so I can test if it exists) and plugging this into article_custom to get all the products in that category:

<article::custom match="Category1=3" limit="999" sort="category1, category2">
   ...
</article::custom>

That’s fine and works a charm. What if I wanted to include articles that are in descendent (sub-)categories of the category given in the URL? Is that possible with some match cleverness? Or do I need to pre-filter the passed value, build the category list as a comma-separated set, and then plug those into a regular article_custom tag. Viz:

<txp:variable name="list_of_cats"><category::list parent='<page::url type="3" />' children="1" break=","><txp:category /></category::list></txp:variable>
<article::custom match="category1" category='<txp:variable name="list_of_cats" />' limit="999" sort="category1, category2">
   ...
</article::custom>

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

#16 2025-05-22 18:42:18

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,758
Website GitHub

Re: Filter by multiple categories

And one more thing, is there a tag-based way to output a nested category list using ul/li tags that mimics the Categories structure, given an arbitrary start point in the tree? I can’t see a way of finding out what ‘level’ we’re at without resorting to PHP and inspecting $thiscategory.


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

#17 2025-05-22 19:06:57

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

Re: Filter by multiple categories

Bloke wrote #339739:

And one more thing, is there a tag-based way to output a nested category list using ul/li tags that mimics the Categories structure, given an arbitrary start point in the tree?

Valueless children?

<txp:category_list parent="daddy" children wraptag="ul" break="li" />

Offline

#18 2025-05-22 19:09:51

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

Re: Filter by multiple categories

Bloke wrote #339738:

What if I wanted to include articles that are in descendent (sub-)categories of the category given in the URL?

Probably <txp:article_custom depth ... />

Offline

#19 2025-05-22 19:26:44

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,758
Website GitHub

Re: Filter by multiple categories

etc wrote #339740:

Valueless children?

Perfect. That needs documenting EDIT: Documented. Well, commited but it’s not showing on the docs site even though it’s allegedly deployed. Hmm…

etc wrote #339741:

Probably <txp:article_custom depth ... />

Is that a 4.9 thing? Doesn’t seem to work on 4.8.8, and it’s not documented. Drat.

No biggie if so. I’ll stick with the longhand approach for now and upgrade to depth when the site is upgraded. Thank you!


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