Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2017-09-20 07:45:10
- bashirnoori
- Member
- From: Afghanistan
- Registered: 2012-10-02
- Posts: 75
how to use sub-categories in <txp:if_category name ... ?
Category: Afghanistan
Sub-category: Kabul
Sub-category: Takhar
Sub-category: Etc…
How i can use category name with it’s own sub-categories in <txp:if_category name="">
may be i think if possible like this:
<txp:if_category name="afghanistan" parent="afghanistan">
Offline
Re: how to use sub-categories in <txp:if_category name ... ?
Salam bashirnoori
You can use this snippet:
<txp:if_category name='<txp:category_list parent="afghanistan" break=","><txp:category/></txp:category_list>' >
if you want to exclude parent category from the if then :
<txp:if_category name='<txp:category_list parent="afghanistan" break="," exclude="afghanistan"><txp:category/></txp:category_list>' >
Look at the wiki : https://docs.textpattern.io/tags/category_list
Offline
Re: how to use sub-categories in <txp:if_category name ... ?
Makes me think that <txp:category_list />
needs link
and title
attributes. Or not?
Offline
#4 2017-09-20 08:24:01
- bashirnoori
- Member
- From: Afghanistan
- Registered: 2012-10-02
- Posts: 75
Re: how to use sub-categories in <txp:if_category name ... ?
Salam Dear Dragondz,
Thank you, that solved the issue :-)
But, it’s good if TXP bring the new option something like this in the future: <txp:if_category name=“cat_name” parent=“1”>
Offline
Re: how to use sub-categories in <txp:if_category name ... ?
@bashirnoori
I think it could be done via a plugin if needed, but why not if the devs are ok with that it s less code to write.
@etc
Hi, oleg, yes why not, i always use category_list as container tag, but it s logical if it has a link and title attribute if used as self closed tag. and by the way is it possible to make break attribute empty instead of “br” ?
Offline
Re: how to use sub-categories in <txp:if_category name ... ?
etc wrote #307125:
Makes me think that
<txp:category_list />
needslink
andtitle
attributes.
If we do it there, does that have implications for other list tags? authors
, images
, linklist
, file_download_list
, …?
Is category_list
special simply because it has parent
? I know we’ve introduced attributes in the past that only work if the tag is used as a single tag vs container, but I don’t know if that’s good general practice. Is it confusing to have an attribute that potentially does nothing depending on how the tag is used?
The form
attribute is (sort of) a special case and falls back (mostly). I can’t remember offhand which way gets priority – container or form – if both are used. I think it’s container. But it’s consistent (I hope!) across all such tags.
You’d have to convince me that there was some overarching benefit to a large set of users before adding link
and title
to list tags. If it’s just useful in one or two specific cases then I’d probably argue that the potential confusion factor outweighs the benefit. But I can be swayed if it makes things more elegant and can be handled consistently and unambiguously.
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: how to use sub-categories in <txp:if_category name ... ?
P.S. a parent
attribute in the <txp:if_category>
/ <txp:if_article_category>
/ tags: now that I would endorse if we could do it in a sensible manner. Can we do something
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: how to use sub-categories in <txp:if_category name ... ?
Dragondz wrote #307127:
Hi, oleg, yes why not, i always use category_list as container tag, but it s logical if it has a link and title attribute if used as self closed tag. and by the way is it possible to make break attribute empty instead of “br” ?
Hi Rabah, this change would not be backwards compatible, I’m afraid.
Bloke wrote #307128:
If we do it there, does that have implications for other list tags?
authors
,images
,linklist
,file_download_list
, …?
You are right, no list tag accepts link
attribute, and that’s probably less confusing. Forget it.
P.S. a
parent
attribute in the<txp:if_category>
/<txp:if_article_category>
/ tags: now that I would endorse if we could do it in a sensible manner. Can we do something
If I understand its meaning we would then have to decide on exclude
and children
attributes. Is grandparent a parent?
If it helps, in 4.7 the parent can be retrieved with
<txp:breadcrumb category="somecat" offset="-2" limit="1" link="" section="" label="" />
offset="-2"
for the parent is debatable, probably offset="-1"
is better?
Offline
Re: how to use sub-categories in <txp:if_category name ... ?
etc wrote #307130:
we would then have to decide on
exclude
andchildren
attributes. Is grandparent a parent?
True. Tricky.
offset="-2"
for the parent is debatable, probablyoffset="-1"
is better?
I’ve not played with this new attribute so I’m not sure what it does yet in real terms. I’m comfortable with whatever you think is best.
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: how to use sub-categories in <txp:if_category name ... ?
Bloke wrote #307131:
True. Tricky.
I’ve not played with this new attribute so I’m not sure what it does yet in real terms. I’m comfortable with whatever you think is best.
A typical <txp:breadcrumb />
looks like ...>grandparent>parent>category
. With offset="-1"
it would output ...>grandparent>parent
, and with offset="-1" limit="1"
just parent
.
Offline
Re: how to use sub-categories in <txp:if_category name ... ?
In 4.7, this will be
<txp:if_category parent name="afghanistan" />
or even (in an article form)
<txp:if_category category='<txp:category1 />' parent name="afghanistan" />
with finer parent matching (father, grandfather) possible too.
Offline
Re: how to use sub-categories in <txp:if_category name ... ?
etc wrote #307187:
<txp:if_category parent name="afghanistan" />...
Does this match category ‘afghanistan’ as well or only the children of afghanistan?
Would this also work: <txp:if_category parent="afghanistan" />
Not sure if this might be clearer: <txp:if_category child name="afghanistan" />
Offline