NEW - Traverse Segments Plugin…
Posted: 07 June 2008 04:35 PM   [ Ignore ]  
Professor
Avatar
RankRankRankRankRankRankRank
Total Posts:  10682
Joined  04-15-2006

Hiya,

Another very very quick plugin made in about a minute so hopefully it works as advertised wink

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"}
<p>Segment was the same!!</p>
{/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 wink

Best wishes,

Mark

File Attachments
pi.traverse_segments.zip  (File Size: 2KB - Downloads: 320)
 Signature 

Shopping Cart Plugin
Full list of add-ons
———————————————————-
Buy me a drink, or two if you like!!

Profile
 
 
Posted: 07 June 2008 05:17 PM   [ Ignore ]   [ # 1 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  491
Joined  07-16-2005

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.

 Signature 

Travis Schmeisser // rockthenroll


Structure: a new way to build ExpressionEngine sites

Profile
 
 
Posted: 07 June 2008 05:20 PM   [ Ignore ]   [ # 2 ]  
Professor
Avatar
RankRankRankRankRankRankRank
Total Posts:  10682
Joined  04-15-2006

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

 Signature 

Shopping Cart Plugin
Full list of add-ons
———————————————————-
Buy me a drink, or two if you like!!

Profile
 
 
Posted: 07 June 2008 05:20 PM   [ Ignore ]   [ # 3 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  491
Joined  07-16-2005

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

 Signature 

Travis Schmeisser // rockthenroll


Structure: a new way to build ExpressionEngine sites

Profile
 
 
Posted: 07 June 2008 05:20 PM   [ Ignore ]   [ # 4 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  491
Joined  07-16-2005

I am using the new code including the new name…

 Signature 

Travis Schmeisser // rockthenroll


Structure: a new way to build ExpressionEngine sites

Profile
 
 
Posted: 07 June 2008 05:21 PM   [ Ignore ]   [ # 5 ]  
Professor
Avatar
RankRankRankRankRankRankRank
Total Posts:  10682
Joined  04-15-2006

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

Best wishes,

Mark

 Signature 

Shopping Cart Plugin
Full list of add-ons
———————————————————-
Buy me a drink, or two if you like!!

Profile
 
 
Posted: 07 June 2008 05:23 PM   [ Ignore ]   [ # 6 ]  
Professor
Avatar
RankRankRankRankRankRankRank
Total Posts:  10682
Joined  04-15-2006
rockthenroll - 07 June 2008 05:20 PM

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

 Signature 

Shopping Cart Plugin
Full list of add-ons
———————————————————-
Buy me a drink, or two if you like!!

Profile
 
 
Posted: 07 June 2008 05:30 PM   [ Ignore ]   [ # 7 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  491
Joined  07-16-2005

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.

 Signature 

Travis Schmeisser // rockthenroll


Structure: a new way to build ExpressionEngine sites

Profile
 
 
Posted: 07 June 2008 05:37 PM   [ Ignore ]   [ # 8 ]  
Professor
Avatar
RankRankRankRankRankRankRank
Total Posts:  10682
Joined  04-15-2006
rockthenroll - 07 June 2008 05:30 PM

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

 Signature 

Shopping Cart Plugin
Full list of add-ons
———————————————————-
Buy me a drink, or two if you like!!

Profile
 
 
Posted: 07 June 2008 05:47 PM   [ Ignore ]   [ # 9 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  491
Joined  07-16-2005

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

 Signature 

Travis Schmeisser // rockthenroll


Structure: a new way to build ExpressionEngine sites

Profile
 
 
Posted: 07 June 2008 05:52 PM   [ Ignore ]   [ # 10 ]  
Professor
Avatar
RankRankRankRankRankRankRank
Total Posts:  10682
Joined  04-15-2006

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

 Signature 

Shopping Cart Plugin
Full list of add-ons
———————————————————-
Buy me a drink, or two if you like!!

Profile
 
 
Posted: 07 April 2009 03:42 PM   [ Ignore ]   [ # 11 ]  
Grad Student
Rank
Total Posts:  91
Joined  01-05-2008

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

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1743, on December 02, 2009 02:47 PM
Total Registered Members: 119406 Total Logged-in Users: 121
Total Topics: 125660 Total Anonymous Users: 54
Total Replies: 661343 Total Guests: 513
Total Posts: 787003    
Members ( View Memberlist )
Active Members:    3000Alexis Moore-JonesAndrew MacphersonAndria RoseAndy HarrisAt the GatesbartblaubiberltdbmillerBob SuttonBrandon C.Bryan SpearmanbryantAXSburton.kentChris ClarkeChris Warehamchrisbarber86Christian SweattCompass360CrucialDamian LewisdaulexdavidlogandemotivederDerek AllardDesignBlokedesignerhandbagsDom.SDouglas ReedDrugs.iedubsakErik ReaganFirestorm Creative StudiosForrest Andersongomacrogregory17grovbergGuy Stephenshearsayhoney4dIan EbdenikennbIngmar GreilJack McDadejackwatkinsJamieFletcherjeffpullingerJordan Moorejoshinfjrutterjtreejulie pkalwebKeith EKippilcrLeon Bienekm2iwm4thewMarco AngeliMarcusNetoMark BowenmarkertimmarramgrassMax LazarMaxEnginemfosMichael HahnMirageMosaikmrscareyNico SmitNikolaKG80Noah KuhnNobis InteractiveOliver NielsenOxygen SmithParisJCPascal KrietePauli HuhtiniemipetattlebaumpieshoppMacedpwilliams1946registryRetro Willyrich69rippeRobdMRoryMacDonaldroryrabbitfieldruraldreamsSafak KayaSam SullivanSarah BraysasjamalSemlyen ITsmartpillStefan RechsteinerSteve FairhurststudiobreakfastSue CrockertimprinttotocvmillsvobtoaviWaielwatershedWEB SecretWes Bakerwuwongyyabdab