Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
[resolved] category_list tag not behaving as expected for nested trees
If my huge category tree is at the root level I can list just the first level cats using this:
<txp:category_list type="article" children="0" wraptag="ul" break="li">
<txp:hide>
Need to manually construct the link.
The 'links' attribute doesn't work for /breadcrumb/title permlink mode.
</txp:hide>
<a href="<txp:section />?c=<txp:category />"><txp:category title /></a>
</txp:category_list>
But if I move the entire tree into a parent caregory name, to keep it compartmentalised from other trees I want to create, this tag:
<txp:category_list type="article" parent="my-group" exclude="my-group" children="0" wraptag="ul" break="li">
...
</txp:category_list>
Shows the entire tree flattened. How do I get just the first level of the sub-tree to list? I tried children="1"
and it made no difference.
The docs say that children="0"
will result in “no children, i.e. only show one level below the parent.” And children="1"
(and above) will “show all nested categories and ‘flatten’ the list at the level n”.
It seems to be applying the ‘n’ case universally if the parent is not root. This is 4.9.0-dev, btw.
Bug? Incorrect documentation? Just me using it wrong?
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
Re: [resolved] category_list tag not behaving as expected for nested trees
Might your server be playing tricks here too? Can not reproduce this one on the demo site, neither locally.
Does it behave the same with a small tree?
Offline
Re: [resolved] category_list tag not behaving as expected for nested trees
Works fine on a small list. My server shows only the first level, as expected with children="0"
.
The only difference between the two trees (beyond the number of items) is that the huge list was generated from code by using insert_nodes()
. But just in case the lft/rgt were wrong, I manually altered one of the items from the huge list via the Txp admin side interface and saved it. That should force a rebuild_tree_full()
right?
Nothing changed. It still shows the entire list with children="0"
.
It’s difficult to replicate this on the demo server completely because it uses messy mode. Here are the settings I’m using on my server:
- Trailing slash = 0.
- Production status = Testing.
- Page template for the section containing the category_list tag is NOT default page.
- Section for this page uses /breadcrumb/title
- Probably others…
Last edited by Bloke (2025-04-13 13:54:45)
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
Re: [resolved] category_list tag not behaving as expected for nested trees
P.S. if you’d like a database dump of my category table for testing, I can bundle it up and send it over?
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
Re: [resolved] category_list tag not behaving as expected for nested trees
Bloke wrote #339517:
The only difference between the two trees (beyond the number of items) is that the huge list was generated from code by using
insert_nodes()
. But just in case the lft/rgt were wrong, I manually altered one of the items from the huge list via the Txp admin side interface and saved it. That should force arebuild_tree_full()
right?
Ah, that might be the reason. No, rebuild_tree_full()
is not called any more on category save, precisely because it takes a very long time for huge trees (see here). But it’s still there, so you can call it manually, hoping the limits won’t be hit.
Offline
Re: [resolved] category_list tag not behaving as expected for nested trees
etc wrote #339519:
No,
rebuild_tree_full()
is not called any more on category save, precisely because it takes a very long time for huge trees… it’s still there, so you can call it manually, hoping the limits won’t be hit.
Ah okay. I just wrote a page template with:
<txp:php>
rebuild_tree_full('article');
echo 'Done';
</txp:php>
Ran it and it showed ‘Done’ almost immediately. Weird. Does that mean it thinks the tree is balanced already?
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
Re: [resolved] category_list tag not behaving as expected for nested trees
Bloke wrote #339522:
Ran it and it showed ‘Done’ almost immediately. Weird. Does that mean it thinks the tree is balanced already?
No, it should rebuild it unconditionally. I’d rather suspect that the tree is corrupted in some way.
Offline
Re: [resolved] category_list tag not behaving as expected for nested trees
etc wrote #339550:
No, it should rebuild it unconditionally. I’d rather suspect that the tree is corrupted in some way.
Yeah, maybe. But I don’t know how if I’m just calling insert_nodes()
for each set of nested items in the list. It doesn’t appear corrupted when using it, and all the elements behave as far as I can tell. The tree is intact, and all sub-items are located under their respective parents. But if I put them all under a single new, top-level subcat and call that category_list tag with children="0"
then I get them all displayed instead of just one level.
So clearly something is screwed up but I don’t know how to debug it.
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
Offline
Re: [resolved] category_list tag not behaving as expected for nested trees
etc wrote #339559:
That might help. A weird issue..
Ack, not a weird issue after all. Fat fingers and stupidity on my behalf. I flattened the list by mistake when I reimported the cats. I just blatted the table completely and reimported everything and it’s now working.
Sorry for the false alarm.
So the only remaining issue is the weird cacheing thing. I’ve sent you a database dump of my category table in case you can figure it out.
Last edited by Bloke (2025-04-18 11:01:41)
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