Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
RFC: expose category IDs; introduce 'category_id' attribute
Currently, we can specify a category name to build content, e.g. a linklist:
<txp:linklist category="orange" />
Note: a category has an internal ID in the same fashion as an article (which can be used for article constructs).
Category names are not unique when 1 or more parents are involved, but their IDs are. Consider the following parents and children, with their respective IDs in parentheses:
Fruit (1)
Apple (3)
Orange (4)
Tomato (5)
Colours (2)
Green (6)
Orange (7)
Red (8)
The linklist becomes less clear on what it will build. If we were exposing the category ID for each category page, it could be more specific in its target(s):
<txp:linklist category_id="7" />
Considerations:
- Is this too edge case-y?
- We’d need to add a div with the ID to each category page (more real estate used).
- We’d need to document it (pretty straightforward).
Guidance and advice very welcome.
Last edited by gaekwad (Today 14:56:22)
Offline
Re: RFC: expose category IDs; introduce 'category_id' attribute
Huh. Never thought of that.
My guess is it’ll choose the “lowest” one of the two values but it’s a wild stab in the dark.
Having the ability to disambiguate with either the id directly as you suggest or perhaps some syntax that permits the id/tree to be suggested in the category name, would help.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
Re: RFC: expose category IDs; introduce 'category_id' attribute
It came about because I’m using a subcategory for each parent called ‘Inactive’ – sort of a holding area that I can shift things in & out of as I’m building…and it dawned on me that I didn’t know how to call each ‘Inactive’ category without renaming them ‘parent-Inactive’ or something similar…which would work, but it’s a little kludgy.
Offline
Re: RFC: expose category IDs; introduce 'category_id' attribute
I should clarify. When I say ID I don’t mean the ID in the table because that changes every time the category tree is rebuilt, or if something is inserted. It’s just the way red-black preorder lists work. What I meant was one way of identifying which of any duplicates you mean.
That may imply either some index value like orange[1] orange[2] etc or, perhaps better, some way of saying it’s in this particular tree.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
Re: RFC: expose category IDs; introduce 'category_id' attribute
Bloke wrote #343059:
When I say ID I don’t mean the ID in the table because that changes every time the category tree is rebuilt, or if something is inserted.
Today I learned. Thanks, Bloke.
Offline
Re: RFC: expose category IDs; introduce 'category_id' attribute
How do you create homonymous categories? There is no unique index, but txp says ‘Link category blah already exists’ when I try. Plugin, maybe?
Offline
Re: RFC: expose category IDs; introduce 'category_id' attribute
That’s a good point. It’s possible to create the same Title but not Name. And the name is the thing you use in the tags to reference which one you mean. I wasn’t thinking straight earlier.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline