We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

NEW - Traverse Segments Plugin…

Development and Programming

Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen

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

       
rockthenroll's avatar
rockthenroll
485 posts
17 years ago
rockthenroll's avatar rockthenroll

This was working before the name change, but now it’s spitting the {segment} out at the very top of my template instead of where I specify it in the template code.

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen

Hi Travis,

Sorry about the name change. Check that you changed the code for the usage on this plugin to this :

{exp:traverse_segments position="0"}
{segment}
{if '{segment}' == "test"}
YAY
{/if}
{/exp:traverse_segments}

That should hopefully work for you?

Best wishes,

Mark

       
rockthenroll's avatar
rockthenroll
485 posts
17 years ago
rockthenroll's avatar rockthenroll

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

       
rockthenroll's avatar
rockthenroll
485 posts
17 years ago
rockthenroll's avatar rockthenroll

I am using the new code including the new name…

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen

Also ensure you download the plugin again from the top of this thread and install it and delete the old one?

Best wishes,

Mark

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen
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

       
rockthenroll's avatar
rockthenroll
485 posts
17 years ago
rockthenroll's avatar rockthenroll

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.

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen
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

       
rockthenroll's avatar
rockthenroll
485 posts
17 years ago
rockthenroll's avatar rockthenroll

No worries. It does work, just getting the errors. Thanks again!

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen

No problems, well apart from the problems that is!

Hopefully someone will see if I have done something that might be throwing those errors though if indeed it isn’t anything to do with your server problems.

Hope it is still useful though.

Best wishes,

Mark

       
Kev-O's avatar
Kev-O
50 posts
16 years ago
Kev-O's avatar Kev-O

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

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.