Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: smd_parent: grab parents up the tree from any category
Thanks for this plugin! Just what I needed.
Offline
Re: smd_parent: grab parents up the tree from any category
hey bloke, i’m having problems using this plugin, or maybe i’m not understanding how it works. my category structure is something like
-Animals
—Dogs
—-Chihuahuas
—-Labs
—Cats
I have 2 articles, one with the category “labs”, the other one with category “cats”.
I’m displaying them in the same form, where I call <txp:smd_parent catnum=“1” title=“1” level=“2” />
If I understand correctly, this should output “dogs” and “cats”, but instead I get “dogs” and “animals”
any clue what’s wrong?
~~~~~~~~~~~~~| monolinea.com | pixilate.com | istockphoto.com/kemie |~~~~~~~~~~~~~
Offline
Re: smd_parent: grab parents up the tree from any category
actually, I was wrong. It outputs “dogs” and nothing.
is there a way to get the same level on both?
~~~~~~~~~~~~~| monolinea.com | pixilate.com | istockphoto.com/kemie |~~~~~~~~~~~~~
Offline
Re: smd_parent: grab parents up the tree from any category
still having this problem, any insight?
~~~~~~~~~~~~~| monolinea.com | pixilate.com | istockphoto.com/kemie |~~~~~~~~~~~~~
Offline
Re: smd_parent: grab parents up the tree from any category
kemie wrote:
actually, I was wrong. It outputs “dogs” and nothing.
Hi Kemie, sorry for the ridiculous delay. I missed this first time round, thanks for the nudge.
The issue is that the pluign only outputs stuff “above” itself in the tree. Thus your first article, being a subcat of ‘Dogs’, displays Dogs. But your second article is actually ‘Cats’ and there is no category ‘above’ it at level 1. It is level 1. Thus it outputs nothing.
Depending on your viewpoint I suppose this could be considered a bug. Although I did mention it in the plugin help, I can’t for the life of me remember why I didn’t allow it to get the current level. Seems bizarre to have to make you decide beforehand whether you want to use this plugin or the built in category tags, especially since this plugin is just an extension to the category tag!
Try this. Edit the plugin code and find Line 35 which reads:
if ($reqLevel > 0 && $reqLevel < $currLevel) {
and swap it for:
if ($reqLevel > 0 && $reqLevel <= $currLevel) {
That’ll output the category if it’s the same level as the one given in the level attribute (or higher) in the tree. Not sure if that has any impact elsewhere but it works with my minimal testing.
Hope that helps. If it has no negative side effects I might make that the default behaviour in the next version. Thanks for highlighting it and sorry again for being so tardy in my response.
Last edited by Bloke (2011-02-19 14:42:17)
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
Online
Re: smd_parent: grab parents up the tree from any category
Shame on you for providing tardy (and FREE) support for your wonderful (and FREE) plugin :).
Your fix seems to work perfectly. I didn’t do any extensive testing either, but it works in my case.
I guess it was a question of me misunderstanding the “level” variable, but I do think the change is a welcome one in any case.
Thank you so much! :)
~~~~~~~~~~~~~| monolinea.com | pixilate.com | istockphoto.com/kemie |~~~~~~~~~~~~~
Offline
Re: smd_parent: grab parents up the tree from any category
Is there any way to test the parent for multiple values? I currently have something like this:
<txp:variable name="parent_topic"><txp:smd_parent/></txp:variable>
[...]
<txp:if_variable name="parent_topic" value="x">Do this.</txp:if_variable>
I want to “Do this” if the parent category is X, Y, or Z, which I could enter as a comma-separated list. But if I’m not mistaken, if_variable can’t test for multiple values as of TXP 4.3.0.
Offline
Re: smd_parent: grab parents up the tree from any category
johnstephens wrote:
Is there any way to test the parent for multiple values?
Not natively. smd_if’s in operator is probably your best bet. smd_multi_select is overkill.
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
Online
Re: smd_parent: grab parents up the tree from any category
Thanks, Stef! I suspected smd_if might be the only way, but I thought I could get away with not installing another plugin. I’ll do it!
Offline
#25 2018-10-05 14:41:44
- hildebruns
- Member
- Registered: 2009-03-10
- Posts: 35
Re: smd_parent: grab parents up the tree from any category
Hello, is there a version for 4.7.1? I have the plugin installed and unfortunately it does not work.
Offline
Re: smd_parent: grab parents up the tree from any category
Interesting. When you say “doesn’t work”, how are you using the tag and what do you expect? There should be nothing in the (very small) plugin that breaks under 4.7.x but there have been many changes to the parser and tags. Something may have affected my kludgy attempt at handling parents.
Depending on what you are trying to do, you may not even need the plugin any more as there have been tag improvements that might help out. So when we find out what it is you are trying to achieve with the plugin, someone may be able to help you find a native solution.
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
Online
Re: smd_parent: grab parents up the tree from any category
In 4.7 <txp:breadcrumb /> can extract (grand-)parents from the category tree via limit and offset attributes:
<txp:breadcrumb category="your_category" limit="1" offset="-1"
section="" label="" wraptag="" />
Also
<txp:if_category category="your_category" parent="1" name="cat1, cat2, cat3" />
will test if your_category is a child of cat1, cat2, cat3.
Offline