Hiya,
Another very very quick plugin made in about a minute so hopefully it works as advertised 😉
This one is for returning the value of a certain URI segment working from the end of the URI backwards.
Usage :
{exp:traverse_segments position="0"}
{segment}
{if '{segment}' == "test"}
YAY
{/if}
{/exp:traverse_segments}
Parameters :
position=”0” This will retrieve the last segment
position=”1” This would retrieve the last but one segment and so on and so forth!
Variables : {segment} Returns the value of the requested segment
Possibilities :
{if '{segment}' == "tests"}
Segment was the same!!
{/if}
Disclaimer - Not too sure if the if conditional above is entirely the correct way to do things. I mean with the ‘{segment}’ part. I think there is probably a better way to do this but it should work as is. Spitting out the {segment} variable should work without any problems though.
If the segment you had requested was in this case equal to tests then the message would be returned
Hope this is of some use to people. Hopefully it will work correctly on all systems too because as I said this was created very very quickly 😉
Best wishes,
Mark
Also, if I use multiple instances I get an error: Notice: Undefined offset: -1 in F:\inetpub\vhosts\domain-here.com\httpdocs\ee\plugins\pi.traverse_segments.php on line 45
Just tried here with multiple instances on the new plugin and all seems to be okay. Hopefully it is now working for you with the new plugin and code?
Best wishes,
Mark
Ok, new copy of the plugin fixed functionality.
Still getting this error (only when logged in though):
Notice: Undefined offset: -1 in F:\inetpub\vhosts\phdmc.controlpanel2.donet.com\httpdocs\ee\plugins\pi.traverse_segments.php on line 46
Notice: Undefined offset: -2 in F:\inetpub\vhosts\phdmc.controlpanel2.donet.com\httpdocs\ee\plugins\pi.traverse_segments.php on line 46
Could it be something weird with the hosting setup? I haven’t been able to get a few things working on it, like removing index.php and “force query strings” is on.
Could it be something weird with the hosting setup? I haven’t been able to get a few things working on it, like removing index.php and “force query strings” is on.
Possibly but as I said I did throw this together very very quickly so it may be something I did. Hopefully one of the moderators will see this thread and download and take a look at the plugin to see if I have done anything wrong.
Sorry that it is causing errors. None here on 4 sites I have tested it on. 2 localhost and 2 real world. Hopefully one of the moderators or one of the other programmers will pick up on anything I have done wrong though.
Best wishes,
Mark
Mark, Love this plug-in, but of course I’m writing because I have a problem. I’m trying to get the category id of a category that matches the same name as a segment in my url.
{exp:traverse_segments position="1"}
{exp:category_id category_group="9" category_url_title="segment"}
{embed=site/video-gallery video-cat="{category_id}"}
{/exp:category_id}
{/exp:traverse_segments}
The problem is that I can’t get the segment value to work in the category_id tag. I’ve tried everything I can think of… {segment}, “{segment}”, “’{segment}’”, segment Nothing seems to work. Not a huge deal, I can work around it, but it’d be slick if I could make this happen.
Any thoughts?
-kev
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.