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

Low Seg2Cat extension

Development and Programming

Low's avatar
Low
407 posts
16 years ago
Low's avatar Low

In short: Low Seg2Cat gives you easy access to category ids so you can use them in your URIs and templates without the use of the Category URL Indicator or custom PHP.

More info and download on my site

       
Sue Crocker's avatar
Sue Crocker
26,054 posts
16 years ago
Sue Crocker's avatar Sue Crocker

Thanks for this, Low. I used it on a client site this morning.

       
notacouch's avatar
notacouch
92 posts
16 years ago
notacouch's avatar notacouch

Where in the parse order chain are the seg2cat global variables? http://expressionengine.com/wiki/Parse_Order/

       
Low's avatar
Low
407 posts
16 years ago
Low's avatar Low

During the path.php Global Variables stage.

       
notacouch's avatar
notacouch
92 posts
16 years ago
notacouch's avatar notacouch

whoa. that’s pretty sweet. thanks :D this is great, looking forward to using it soon.

       
Brett DeWoody's avatar
Brett DeWoody
140 posts
15 years ago
Brett DeWoody's avatar Brett DeWoody

I’ve been using this on a site in development and it was working great.

But the other day I started getting this error:

Warning: Invalid EE Conditional Variable: {if segment_3_category_id != ""} in path/to/admin/core/core.functions.php on line 2804

My template contains {if segment_3_category_id != ""}, but its inside an IF loop that shouldn’t be getting executed on the particular pages where the error is being thrown.

I can’t think of anything I changed that would have caused this.

Have you seen this error before?

       
Low's avatar
Low
407 posts
15 years ago
Low's avatar Low
Have you seen this error before?

I have not, at least, I think I haven’t. And as it should behave like any other global variable, I’m not sure where the problem lies. Have you tried this syntax?

{if "{segment_3_category_id}" != ""}
       
Brett DeWoody's avatar
Brett DeWoody
140 posts
15 years ago
Brett DeWoody's avatar Brett DeWoody

Wait, that doesn’t work actually. I thought it did at first. It throws the following error:

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /path/to/core/core.functions.php(634) : eval()'d code on line 23
       
Austin Siewert's avatar
Austin Siewert
129 posts
15 years ago
Austin Siewert's avatar Austin Siewert

Low, first off, great extension and thanks for sharing!

I got an oddity that is baffling me. I have the ext. looking at the segment_2, and on some pages it grabs the correct ID, and on others it doesnt. So I ran a little test to make sure EE was outputting the correct ID, and sure enough it does, but Seg2Cat doesn’t see the ID?

Double checking ID’s:

{categories}{category_id}{/categories} | 
            {segment_2_category_id}

And this is the template that works on most, but not all categories:

{exp:weblog:entries weblog="project" limit="1" status="Open|Featured" category="{segment_2_category_id}" dynamic="off" orderby="random" disable="category_fields|member_data|pagination|trackbacks"}
       
Low's avatar
Low
407 posts
15 years ago
Low's avatar Low

Hey Siebird,

Are you getting a wrong ID or none at all? If you’re getting a wrong ID, you might want to check the unique-ness of the categories, as explained on my site (Caveats).

Otherwise: - What version of Seg2Cat are you using? - What version of EE are you using? - What version of PHP are you using? - Is this happening to a single category or all? - Is this happening on a single template or all? - What is the full URI when this is happening?

       
Austin Siewert's avatar
Austin Siewert
129 posts
15 years ago
Austin Siewert's avatar Austin Siewert

Hey Low,

None at all.

  • Just installed the latest (1.2) b/c I thought maybe that was the issue.
  • 1.6.8 20090723
  • 5.2.6
  • a couple,not all
  • single template, which make its odd
  • PM you the link…
       
Low's avatar
Low
407 posts
15 years ago
Low's avatar Low

After taking a quick look in your templates, here’s what’s happening: the url_title in segment_2 belongs to an entry, not a category. Some entry url_titles are identical to the categories they’re assigned to – that’s why sometimes you do get an id back. Solution: link to the category itself, not the entry belonging to that category.

       
Austin Siewert's avatar
Austin Siewert
129 posts
15 years ago
Austin Siewert's avatar Austin Siewert

Cool, I was unaware this extension only worked for categories, I thought it would grab any id’s from any segment.

I was able to fix those entries by using the same url_title as the category_url.

       
Eric Nance's avatar
Eric Nance
25 posts
15 years ago
Eric Nance's avatar Eric Nance

In a MSM setup, does Seg2Cat allow the same category names across sites? I realize the caveat about not having the same category names in a single site, but didn’t know if this was also the case across sites in an MSM setup.

I’m using the same code on two sites in one MSM installation. On Site A the code is working perfectly. On Site B, the code doesn’t pull the entries from the correct segment variable. Instead, it’s displaying ALL entries.

       
Low's avatar
Low
407 posts
15 years ago
Low's avatar Low

Low Seg2Cat only looks for categories belonging to the current site. If no match was found, it will return an empty string. So, if you’re using code like this…

{exp:weblog:entries weblog="default_site" category="{segment_2_category_id}"}

…and no category is found in {segment_2}, the weblog entries won’t be filtered, thus showing all entries.

       
1 2

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.