Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2024-05-01 14:11:31
- raminrahimi
- Member
- From: India
- Registered: 2013-03-19
- Posts: 278
How to list nested sub categories articles?
How I can list the articles of sub categories like I have the main category News and all other sub categories Politics, Security, Sports, etc… belong to News category.
Now I want to list the articles belong to all those sub or nested category of News -> politics, security, sports etc…
<txp:article_custom category="here-news-subcategories" limit="10>...
Offline
Re: How to list nested sub categories articles?
I usually do this in two steps:
- Get children categories of parent “news” and save in variable
- Output your article_custom tag with the variable as the category attribute
<txp:variable name="news_cats" trim>
<txp:category_list parent="news" exclude="news" children="1" break=","><txp:category /></txp:category_list>
</txp:variable>
<txp:article_custom category='<txp:variable name="news_cats" />' limit="10" … />
Remember to use single quotes around the tag in the attribute.
(You can do this as a tag-in-tag without the variable but it quickly becomes hard to read.)
It wasn’t clear if you also want the parent “news” category too. If you do, just remove the “exclude” attribute. If you want multiple levels of sub-categories, use the attribute children="2"
(or however many levels you want). See the docs for category_list for more information
TXP Builders – finely-crafted code, design and txp
Offline
Re: How to list nested sub categories articles?
As usual, there are many ways, you should describe your requirements more in details. Probably, depth
will do?
<txp:article_custom category="news" depth="1" ... />
Offline
Re: How to list nested sub categories articles?
Hi Oleg
What the “depth” attribute ?
I searched doc site for “depth” i got nothing, is it mentioned somewhere ?
Thanks
Offline
Re: How to list nested sub categories articles?
Hi Rabah,
Dunno why depth
attribute of <txp:article(_custom) />
is undocumented. Maybe it’s a 4.9 thing, maybe an oblivion. The idea is to match the subcategories of certain levels:
category="news" depth="0"
(default) matchesnews
categorycategory="news" depth="1"
matchesnews
childrencategory="news" depth="1-2"
matchesnews
children and grand-childrencategory="news" depth
matchesnews
and its descendants
and so on. Negative depth
might match parents too, I don’t remember.
Offline
Re: How to list nested sub categories articles?
Thanks Oleg,
I think it s super useful.
The re is no mention about depth for article_custom in History.txt then i dont know when it has been set.
Cheers.
Offline
Re: How to list nested sub categories articles?
Yes, it can be handy. If history serves, depth
was introduced in 4.8.0, but the docs did not follow. This guy’s fault (kidding :-)
Offline