EE: Low Seg2Cat extension

This ExpressionEngine extension will make it easier to work with categories. This post now provides a place for support for the Low Seg2Cat extension.

Download and docs for Low Seg2Cat can be found in the Software section

November 4th 2008 | Add-Ons, Categories, ExpressionEngine, Segments | 125 comments

Comments

  1. 1 Peter November 4th 2008, 19:29

    Hi Low

    Looks nice, we’ve always handled this with PHP as you can imagine, too bad this didn’t come out two weeks sooner, we could have used this in a project that is nearly finished.

    Thanks for your work, will definitely consider this in future projects.

  2. 2 Ryan Masuga November 4th 2008, 19:36

    Low, I’ve always used PHP on my templates to get the category ID from a segment in the URL, so this looks good to me. I think I may be able to use this on my current project. Also adding this to the devot:ee (devot-ee.com) add-on library.

  3. 3 Erwin Heiser November 5th 2008, 15:34

    I must admit I underuse categories, but this looks seriously sweet :)

  4. 4 Zac November 10th 2008, 01:11

    Nice addition to the EE plugin world! I definitely have a use for this on a site I’m working on now. Thanks!

  5. 5 Don Ambridge November 14th 2008, 00:49

    Brilliant. Love you.

  6. 6 Joerg January 2nd 2009, 12:50

    Is there a chance to get the {segment_n_category_url_title} ?
    Would be awesome!

  7. 7 Joerg January 2nd 2009, 22:38

    I just figured it out myself > I haven’t got a clue what I’m doing - but that seems to work:
    add this line after line 106:

    $data[’segment_’.$ids[$row[’cat_url_title’]].’_category_url_title’] = $row[’cat_url_title’];

    This now works fantastically well for breadcrumbs etc ….

  8. 8 Low January 3rd 2009, 12:03

    Joerg, that hack isn’t even necessary. This extension checks the url segments and compares them to the category_url_titles. So, if a category is found, then the segment equals the category_url_title.

    In other words, {segment_n} == {segment_n_category_url_title} :-)

  9. 9 Stanislav Majerski January 13th 2009, 19:28

    Just started using this plugin. Great help. As noted sometimes is nice to get rid of the CATEGORY word in the URL.

    Thank you

  10. 10 Tristan Bailey February 27th 2009, 04:54

    This looks quite nice and will save the need for category in the url which I don’t like. Will give it a whirl soon.

  11. 11 Tory April 7th 2009, 23:41

    How is it used?? Can someone please post an example so I know how to use it?

    Thanks!

  12. 12 Stan April 8th 2009, 12:45

    Tory. See if this example will clarify:

    URL: example.com/animals


    {exp:weblog:entries weblog="weblog_name" category="{segment_1_category_id}" }
    List only entries that are assigned to the category named animals (in Category URL Title)
    {/exp:weblog:entries}

    This helps to create cleaner URLs and get rid of the “category” or “c” word from the url.

  13. 13 Tory April 8th 2009, 14:49

    Thanks for the example, appreciate it. But…

    It seems to work perfect on some categories, but not at all on a few. Seems that if the category id is more than one word (for example, I have a category that has two words and the url has a hyphen separating the words) it’s not working.

    I tried using this:

    {exp:weblog:entries weblog=”portfolio” category=”{segment_3_category_url_title}” }

    But it’s not working either. Any help would be greatly appreciated.

    Thanks.

  14. 14 Low April 8th 2009, 14:57

    Tory, {segment_3_category_url_title} is not available, since it would be exactly the same as {segment_3} and therefore pointless. The category parameter in the weblog:entires tag expects an ID, so you’d have to use {segment_3_category_id}. And you should probably also add dynamic="off" to the weblog:entries tag.

  15. 15 vani May 12th 2009, 22:20

    Hi - Is there an example on how this extension would be used?

  16. 16 Low May 12th 2009, 22:43

    Vani, you can use the variables made available with this extension in several ways. There is no one single purpose other than having the said variables available. So, if there’s a category url_title in the url, you could use <title>{segment_3_category_name}</title> as your page title or {exp:weblog:entries weblog="my_blog" category="{segment_2_category_id}" dynamic="off"} to get all entries from the given category without the use of the Category URL Indicator.

    In short, just read the ‘What does it do’ bit and then ask yourself: can you think of an example on how this extension could be used?

  17. 17 Nathan Pitman May 19th 2009, 23:44

    Hi there, will this work with gallery categories, or would it be possible to add a parameter to specify that it does? :)

  18. 18 Low May 19th 2009, 23:59

    Hey Nathan. I’m afraid Gallery categories aren’t supported. Yet. :)

  19. 19 Todd May 28th 2009, 13:52

    Thanks Lodewijk (how do you pronounce that?) for your excellent work here. I will definitely be using this beautiful solution in the future.

  20. 20 pirco June 3rd 2009, 05:44

    hi, can you list requirements? I get

    “MySQL ERROR:

    Error Number: 1146

    Description: Table ‘OUexpEng.EE__extensions’ doesn’t exist”

    thanks

  21. 21 pirco June 3rd 2009, 19:14

    is it possible that this extension won’t run in EE 1.6.7?
    trying to enable it, I get the error above.

  22. 22 Low June 3rd 2009, 22:28

    @pirco: as far as I know, this extension works with the latest EE build. Do other extensions work?

  23. 23 pirco June 3rd 2009, 22:31

    yes.
    I’m on PHP5, btw.

  24. 24 Low June 3rd 2009, 22:45

    Pirco, can you try a fresh copy? I made a small change — see how that works out.

  25. 25 pirco June 3rd 2009, 23:32

    yup, that works!
    thanks for the personal attention. much appreciated.

  26. 26 earph June 5th 2009, 00:08

    I’ve seen the many examples in the comments, but I’m still having a hard time wrapping my brain around how to implement this.

    Ideally, I would like my URL to look like: http://www.domain.com/category/movie-title/

    I appreciate any other advice you could give. Thanks!

  27. 27 Mark @ Alchemy United June 5th 2009, 04:08

    WOW! Sweet! If this works then I think you just saved my life. No need for /category/. No need to pass Cat_IDs. Thank you for reading my mind.

    I have a question… (And it might be pre-mature since I haven’t read eveything nor even installed this yet) What happens if the segment is an entry URL? Or is it assumed that dynamic=”off”?

  28. 28 Low June 5th 2009, 09:01

    @earph and @Mark: setting up URL structures is totally up to you. In EE, you can set up any kind of URL structure you want, using the {path="seg1/seg2"} variable.

    This extension does not build URLs for you, it merely looks at the current URI and fetches matching categories, which you can then use in your templates. This means that any match with a category url title is available. If the segment is an entry url title, and it doesn’t match a category url title, then the {segment_n_category_...} variables will be empty. You get the variables, you decide how to work with them.

    This means, earph, that you could use the URL structure you want, but I can see a problem there. The first segment is usually used to identify the template group. This is good for keeping your templates structured and catching 404’s. In your case, the first segment is a dynamic value, which you’d have to read and manage in the index template of your default template group, which would be a challenge. You could also create as many template groups as there are categories, but that’s not something I’d recommend.

  29. 29 earph June 5th 2009, 18:52

    Thanks for the response low!

    I managed to mix your extension in with the method found here: http://fortysevenmedia.com/blog/archives/setting_up_custom_category_url_structures_in_expressionengine/

    It did allow me to set up the path exactly as I request, and you’re right IT IS a dynamic value. I hope it doesn’t make things too complicated down the road. Do you think I’ll have a problem using the method above? It seems like it’s handling the dynamic value really well.

  30. 30 Mark @ Alchemy United June 5th 2009, 21:50

    Hey Low. Two more questions, if you don’t mind:

    1) “If no matching category is found for a segment, an empty string is returned.” So the global is still created for the segment for the value is ” “, correct?

    2) Does this work with Multi-Site Manager (MSM)?

    This plugin looks great for how we’ve been approaching EE based sites. Perfect even! Now can someone tell me how to get rid of segment_1 so I can do mysite.com/category-A instead of mysite.com/some-template-folder/category-A? Basically I want my “root” / core pages to appear there and then use template folders for particular areas (e.g. blog, freelance, etc.)

    Thanks again. I

  31. 31 mahalie June 11th 2009, 22:39

    Almost done with a new section of my site using this extension but am having difficulties with pagination, even using paginate_base - it just loops!

    Has anyone figured out pagination use with low seg3cat?

  32. 32 Low June 12th 2009, 08:33

    @Mark: 1: Correct. 2: Yes.

    You’ll need to set up some logic in the index template of your default template group. Try using embeds. Something like this:

    {if segment_1_category_id != ''}{embed="group/template_1"}{/if}
    {if segment_1_category_id == ''}{embed="group/template_2"}{/if}

    @mahalie: Dynamic pagination will be flaky if you use this approach. One way to work around this, is using the offset="" parameter and setting its value in another segment. You could end up with URIs like this: /group/category1/50/ and use this weblog:entries tag: {exp:weblog:entries category="{segment_2_category_id}" offset="{segment_3}" dynamic="off"}. You’d have to calculate the offset value yourself, though.

  33. 33 Peter June 12th 2009, 08:42

    We’ve implemented a multi-level hierarchical navigation by using only categories lately on a client site, for pagination, we had to use the dynamic="off" approach by applying a small hack to the EE core: http://expressionengine.com/wiki/Enable_pagination_with_dynamic_off

  34. 34 Steve Abraham June 19th 2009, 16:05

    Hi Lodewijk,

    Would it be possible to update this so it accepts site=”site_short_name”, so on an MSM environment you can specify which site the category group belongs to?

    Cheers!
    Steve.

  35. 35 Steve June 24th 2009, 18:01

    Can’t seem to get the category name, where the category has two words. Using dynamic=’off’. I see someone else mentioned this earlier. Is there a bug here? Or is there a fix?

  36. 36 Steve June 24th 2009, 18:11

    Forget that last query - my template wasn’t updating for some reason. No bug :)

  37. 37 Low June 24th 2009, 18:11

    @Steve: what are you trying to do? I got the feeling it’s not this extension you’re having trouble with, but rather with the thing you’re trying to accomplish.

    @Steve Abraham: this extension already is MSM-friendly — it only checks the categories belonging to the site you’re viewing.

  38. 38 Mark @ Alchemy United June 24th 2009, 23:53

    Hello again Low…

    Ok, still sounds great. I’m really anxious to try this. BUT… could you be so kind as to look at this EE forum topic I have going and offer your comments?

    It would help a lot. Thx man.

    http://expressionengine.com/forums/viewthread/121037/#599638

  39. 39 Mark @ Alchemy United June 24th 2009, 23:56

    Low…

    One more Q… What about category custom fields? Do you global those as well?

  40. 40 Low June 25th 2009, 12:51

    @Mark: if you’re having trouble with your site, please ask the EllisLab support crew — it’s what they’re there for. :) Seg2Cat does not include custom fields, because I wanted to make it simple and lightweight. You can use PHP or the Query module instead.

  41. 41 Mark @ Alchemy United July 13th 2009, 19:48

    Hello again Low!

    First, used your extension to “convert” a site I was about to take live. Brilliant! Gotta love those cleaner URLs

    With regards to my other request (EE forum), it was related to multi-site manager, maybe this extension, and trying to provide the idea solution to the client. It wasn’t “tech support” as much as EE theory.

    Thanks again. As I use this going forward I’m going to have to tack on a fee to my invoices to kick back to you :) Cheers!

  42. 42 notacouch July 21st 2009, 00:15

    Hi Low

    I seem to have encountered a problem, don’t know if this was reported or not, but if there are multiple segments that are the same only one will get parsed out e.g.
    /template_group/category_url_title/entry_title
    where seg 2 and 3 are the same, 2 will not get assigned.

    Made my own fix for it

    $ids = array(); before the first foreach loop then inside after the data

    $escaped_seg = $DB->escape_str($seg);
    if( isset( $segs ) && in_array($escaped_seg, $segs) )
    {
    if( ! isset( $duplicates ) ) $duplicates = array();
    if( ! isset( $duplicates[$escaped_seg] ) ) $duplicates[$escaped_seg] = array( $ids[$escaped_seg] );
    $duplicates[$escaped_seg][] = $nr;
    }
    //
    $ids[$escaped_seg] = $nr;
    $segs[] = $DB->escape_str($escaped_seg);

    then later.. just to give you the idea

    // overwrite values in data array
    $iter = 0;
    $iter_end = 1;
    $temp_ids = array( 0 => $ids[$row['cat_url_title']] );
    if( isset ( $duplicates[$row['cat_url_title']] ) )
    {
    $iter_end = count($duplicates[$row['cat_url_title']]);
    $temp_ids = $duplicates[$row['cat_url_title']];
    }
    for($iter; $iter < $iter_end; ++$iter)
    {
    $data['segment_'.$temp_ids[$iter].'_category_id'] = $row['cat_id'];
    }

    it got the job done =)

  43. 43 Benek July 28th 2009, 06:32

    Awesome extension. Just what I need and saved me a top of time figuring out how to do this manually. Thanks!

  44. 44 heaversm July 28th 2009, 14:06

    lifesaver - thanks!

  45. 45 Boyink September 10th 2009, 21:11

    Any chance this could also return parent category information? I’m doing some menu work and need to know the ID of the parent category of the current category so I can set the menu state correctly.

  46. 46 Low September 11th 2009, 15:06

    Hey Mike. Sure, that’s actually quite an easy addition. As soon as I get Git working on Snow Leopard again, I’ll update the extension. Or just send me an email if you need it straight away.

  47. 47 Boyink September 11th 2009, 16:32

    Thanks!

  48. 48 3Easy October 19th 2009, 16:18

    Low,

    The deeper one delves into EE, the greater the love of this community. About to code up something along these lines, I realise I don’t have to because the hard work has been done. Thank you, love you though we’ve never met.

    Muchos,
    3Easy.

  49. 49 akc October 31st 2009, 01:03

    This is extremely useful, and I’m thrilled that it’s available to use it on my current project. It’s perfectly handy in creating a tagging system, using EE’s categories, with clean URLs like http://somesite.com/tag/tagname for pages that show all the entries in a particular tag (category). Thanks! (And thanks to Boyink! for referring me to it in the forum.)

  50. 50 Lee December 9th 2009, 12:46

    “If no matching category is found for a segment, an empty string is returned.”

    In EE2 I’m not finding this to be the case, for example if segment 4 of a url is not in use, the raw text {segment_4_category_name} is returned and not an empty string.

    Super useful code - many thanks.

  51. 51 Low December 9th 2009, 12:53

    Lee, if there is no {segment_4}, then {segment_4_category…} variables will not be set in the first place. In those cases, it’s better to do a check with a conditional: {if segment_4} [...] {segment_4_category...} [...] {/if}

  52. 52 Paradise February 1st 2010, 19:45

    Hi,

    it doesn’t work in the new EE 2.

  53. 53 Low February 1st 2010, 20:05

    Paradise, version 2.2 does.

  54. 54 Paradise February 3rd 2010, 10:06

    Hi Low,

    i have the same proplem with Low Replace. If i go to Extensions or Plugins the github site shows up. On Seg2Cat i get this php errors at the bottom.

    Message: Class Low_seg2cat_ext does not exist in (/mypath/expressionengine/third_party/low_seg2cat/ext.low_seg2cat.php)
    Filename: cp/addons_extensions.php
    Line Number: 121

    and

    Message: Cannot modify header information - headers already sent by (output started at /mypath/expressionengine/third_party/low_seg2cat/ext.low_seg2cat.php:15)
    Filename: core/Common.php
    Line Number: 421

    Another question is - does now everything (plugin, ex, module go in the third_party folder?

  55. 55 Low February 3rd 2010, 10:15

    Paradise, EE2 works with 3rd party packages. That means everything is put into the third_party folder, in its own directory. By the look of your paths, this is the case.

    I cannot replicate your error. What 2.0 version are you using? The free trial, the freelancer or the (non)commercial version? Also, are there any other add-ons installed?

  56. 56 Paradise February 3rd 2010, 10:36

    They are the only add-ons. You know i truncated the path :-)? The full path is

    /var/www/work.mydomainCOM/htdocs/something.de/system/expressionengine/third_party/low_seg2cat/ext.low_seg2cat.php

    Its v2.0.1pb01 and a free ride :-)

  57. 57 Low February 3rd 2010, 11:03

    Paradise, still cannot reproduce. Can you install other add-ons without problems?

  58. 58 Paradise February 3rd 2010, 13:17

    Ok, for a test i took Ryan Irelan’s “First Timer” extension and it works…

  59. 59 Low February 3rd 2010, 14:25

    Looks like to me you’re trying to install version 1.x instead of the EE2 compatible version v2.2 (grab it at github).

  60. 60 Paradise February 3rd 2010, 15:25

    Downloaded it again (what i did 3 times before) and the CP allways shows the github site. I found a thread in the EE forum where somebody had the same problem with another add-on.

    Can i not post links here?

  61. 61 Low February 3rd 2010, 15:41

    You can post links here. But maybe something is going wrong with the download from GitHub. I’ve zipped up a version you can download here: Low Seg2Cat v2.2.

    Be sure to delete the other versions you downloaded.

  62. 62 Paradise February 3rd 2010, 16:01

    Cool it works. So now i need also Low Replace :-)

    Seems to be a github problem, cause the guy in the forum had the same problem with another add-on from github.

  63. 63 Low February 3rd 2010, 16:16
  64. 64 Paradise February 3rd 2010, 16:28

    Thanks Low for your time/help. Now everything works. I’m to stuppid for github? Just right click and save - or?

  65. 65 Low February 3rd 2010, 16:32

    To download from GitHub, just click the ‘Download Source’ button on the top right of the project page, below the search form and main menu.

  66. 66 daulex February 8th 2010, 18:35

    first of all, thank you for the plugin.

    question:
    {if "{segment_2_category_id}" == "" OR "{segment_2_category_id}" == "{segment_2_category_id}"} aaaa {if:else}bbb{/if}

    doesn’t work even though {segment_2_category_id} is returned when there is no segment 2.

    Is there a workaround? Why can’t it just be “” (nothing) instead of echoing the name of the function?

  67. 67 Low February 8th 2010, 18:47

    Daulex, what are you trying to accomplish? By the looks of it, something like this might be more appropriate:

    {if segment_2}{if segment_2_category_id}aaa{if:else}bbb{/if}{/if}

    But beware — using this code as input for another tag will not work, because of the parse order.

  68. 68 daulex February 8th 2010, 18:57

    Thank you for the swift reply.

    That is pretty simple. I have yet to test it, but that’ll work.

    The question remains, any chance the plugin could be improved to return a blank when the segment is not present?

  69. 69 daulex February 8th 2010, 19:02

    I’m simply trying to pull the appropriate category based on the url segment. While pagination available at any stage.

    I reworked the code you provided to:
    {if segment_2}{if segment_2_category_id}{segment_2_category_id}{if:else}{segment_1_category_id}{/if}{/if}

    I’m getting this error Invalid EE Conditional Variable: {if segment_2_category_id}, which is what you probably warned me about.

    Thank you for taking the time to help me man.

  70. 70 daulex February 8th 2010, 19:09

    Sorry for what’s looking like spam now, that only appears if there is no segment_2, otherwise works as expected, until I put it where I need it.

    How’s this for a line of code:
    {exp:channel:entries channel="products" limit="1" paginate="bottom" category="{if segment_2}{if segment_2_category_id}{segment_2_category_id}{if:else}{segment_1_category_id}{/if}{/if}"}

  71. 71 Low February 8th 2010, 19:15

    Daulex, putting an advanced conditional (the one with {if:else}) inside a parameter will not work. Make sure you know what the value is of the variable before using it as a parameter value.

    So, try this instead:

    {if segment_2}{preload_replace:the_category="{segment_2_category_id}"}{/if}
    {if segment_1}{preload_replace:the_category="{segment_1_category_id}"}{/if}
    {preload_replace:the_category=""}
    {exp:channel:entries category="{the_category}"}
    ...
    {/exp:channel:entries}

  72. 72 daulex February 8th 2010, 19:38

    Dude, I love you.

    That works… until I start using pagination :D

    site.com/cat/ works
    site.com/cat/P0 - breaks the whole thing as the_category goes blank :( which is why I was going to rely on using segment_2_category_id where you are now using if segment_2 in the first place.

    I’m a wordpress heavyweight and really can’t believe that something that is so simple in wordpress is such a pain in ee. Really appreciate your time man.

  73. 73 Low February 8th 2010, 19:49

    Then there’s just one option, really. Use PHP on input in your template. That way you can check the value of the segments and set variables accordingly.

    But since that has little to do with the Seg2Cat extension, I suggest you check out the EE Forums for help on that.

  74. 74 daulex February 9th 2010, 11:20

    Thank’s Low, I understand the way it should work, however the only reason I asked you for help was the fact that your plugin echoes it’s own function call when there is no segment, which is extremely confusing. I just want to know if that can be avoided, as there is no way check against it.

    Something as logical as
    {if "{segment_2_category_id}" == "" OR "{segment_2_category_id}" == "{segment_2_category_id}"}

    Does not work. Which is why I asked you if the plugin can be improved.

  75. 75 Low February 9th 2010, 11:25

    Slight difference, the variable isn’t replaced if the segment isn’t present. If it should be replaced, then I need to set all variables for each possible segment (I believe 9 is the max at the moment). So, that means setting 9 x 5 = 45 variables, even when there’s no need.

    I’ll need to look into performance before I make such changes, but your feature request is noted.

  76. 76 Paradise February 16th 2010, 08:12

    Hi,

    how about a {last_segment_category_id}.
    Maybee it can be done with the {last_segment} motification from the path.php.

    I need to get the id from the last segment into the Channel/Weblog Entries Tag and don’t know how.

  77. 77 Low February 16th 2010, 11:52

    Paradise, I’ve updated the extension. There’s a new setting ‘Set all segments’, which will initiate all 9 possible segments. That should cater to your needs.

  78. 78 Brendan February 19th 2010, 11:19

    Hi Low

    What’s the chance of getting {category_n_group_name} as well?

    Plugin is pure gold by the way.

  79. 79 Low February 19th 2010, 11:28

    Hey Brendan,

    Those chances are slim. I want to keep this extension as lightweight as possible, by only querying one table once. Adding the group name will require joining another table, which won’t be necessary in most cases.

    You could use the query module, though. Something like this should do it:

    {exp:query sql="SELECT group_name FROM exp_category_groups WHERE group_id = '{segment_n_category_group_id}'"} {group_name} {/exp:query}

  80. 80 Brendan February 19th 2010, 14:34

    Thanks Low, worked a treat.

  81. 81 Mike February 20th 2010, 23:14

    Hi - this doesn’t appear to be working for me - I’ve downloaded v1.3 and installed the language and extension files to the proper directories, but nothing shows up in my extensions list. When I attempt to run a trace (ex: {segment_4_category_id}) within the weblog entries tag, the tag reads as its literal interpretation, and nothing is rendered. Any ideas? I’m using expression 1.6.8

  82. 82 Johan Baaij March 6th 2010, 17:16

    I get this in my extensions manager:

    No direct script access allowed

    What could be wrong :(?

  83. 83 Boyink March 22nd 2010, 22:18

    Hey Low -

    Having an odd issue on a client site where I’m using category=”{segment_4_category_id}”. I have a couple of multi-word category names where it works if I use underscores as separators, but not if I use dashes. One is “quick-release”, and the other is “fasteners-and-screws”. Other multi-word category names work fine. Any ideas?

  84. 84 Mike Heavers March 22nd 2010, 22:20

    Hey - love the extension. Question - is there a way to target the topmost parent category? Basically I have a 3rd level category, and I want to write a conditional that says “if segment_4_parent_parent_category_id == category_id” do something. Thanks in advance.

  85. 85 Low March 22nd 2010, 22:27

    Hey Mikes. :)

    Boyink: only thing I can think of why it doesn’t work as expected is that there are multiple categories with that url_title. Is that the case, perhaps?

    Heavers: I try to keep seg2cat as light weight as possible, so that info isn’t available — you’ll have to use the Query module or some custom PHP to accomplish that.

  86. 86 Boyink March 22nd 2010, 22:35

    Well, I wish it were that easy. Those category url titles are unique in the install.

  87. 87 Low March 22nd 2010, 22:40

    Hmmm, okay. Are the {segment_4_category…} variables generating the any output for those category segments?

    If possible, you could give me access to the EE install?

  88. 88 Boyink March 22nd 2010, 22:48

    Yes - I’m using the name on the page, and if I display the ID it renders as well. I’ll shoot you access via email.

  89. 89 Low March 22nd 2010, 22:58

    *cough* dynamic=”off” *cough*

  90. 90 Boyink March 22nd 2010, 23:06

    Well - that’s odd. I hadn’t considered that because of the notes in the docs on specifying categories made it sound like by specifying a category id you were essentially telling the weblog entries tag to not be dynamic to begin with.

    Odder that it only affected a couple of the categories.

    Regardless - once again I prove that there’s always more to learn!

    Thanks Low!

  91. 91 Low March 22nd 2010, 23:13

    My idea is, that if you don’t need the tag to be dynamic, best to turn it off. It’s also a tiny bit faster in processing.

  92. 92 Mike Heavers March 24th 2010, 16:45

    Hi - for some reason this works for a little while, then will suddenly give me an error message:

    Warning: Invalid EE Conditional Variable: {if segment_4 == “home” OR segment_4_category_parent_id == “51″} in /home/***/public_html/manage/core/core.functions.php on line 2773

    If I remove the segment_4_category_parent_id piece, it functions fine again (and I can even add that piece back in and have it work for awhile). Any idea why this is happening?

  93. 93 Low March 24th 2010, 16:52

    Hi Mike,

    This looks like something you should ask the EllisLab team. If the problem is intermittent, it most likely has something to do with the way conditionals are parsed.

    You can take Low Seg2Cat out of the equation, because it already did its work — register segment_n_category_x variables to the global variables array. The rest is done by EE’s template parser, so if something goes wrong there, it has to do with the way EE parses its global variables.

    Only advice I can give you is to make sure you’re running the latest EE build.

  94. 94 Fred Carlsen April 7th 2010, 00:33

    Mike and Low, after experimenting with this, my inexperienced eye tells me that its due to the parse order of things. Since we are using advanced conditionals, there is something being messed up between EE and Seg2Cat.

    I fixed this after some headscratching by writing less efficient simple IFs (aka boring ones).

    For example, in use with Template Morsels: {if segment_1}
    {if segment_2==""}
    {if segment_1_category_id=="" }
    <!-- INGENTING MED OBJEKT: -->
    {exp:template_morsels:fetch name="vis-objekt" type="ingenting" blog="{my_weblog}" segment_1="{segment_1}"}
    {/if}
    {/if}
    {/if}

  95. 95 Fred Carlsen April 7th 2010, 00:44

    I forgot to mention - I don’t know if my explanation is correct, or what is causing this.

    I am using Seg2Cat 1.3 with EE 1.6.8, and after taking a look at the parse order list in the wiki, I would assume my advanced conditionals would work together with the Set all segments option turned on.

    Instead, my log was telling me otherwise: Invalid EE Conditional Variable: {if segment_1_category_id!="" && segment_2!=""}

    Invalid EE Conditional Variable: {if segment_1 && segment_1_category_id=="" && segment_2==""}

    Since segments are available and set before anything is parsed/evaluated, it should not give us that error - Am I right? (I understand this might be EllisLab-territory, but I hope you can help to shed some more light on this).

    And Low, your a hero for making this. I have only recently become an active EE-user, but this sorted out one of my first and worst headaches.

  96. 96 Albert Warnecke May 7th 2010, 11:14

    Hi Low,
    just a short question regarding the naming conventions
    I assume, that Seg2Cat for EE 2 doesn´t accept category names with special characters and names, that consists of more than 1 word.
    So, something like “alte Möbel” won´t work.
    Is this right?

  97. 97 Low May 7th 2010, 11:20

    Fred: Check your EE 1.6.8 build. I think there were some issues with conditionals in earlier builds of that version.

    Albert: Actually, Seg2Cat doesn’t really accept anything. It just looks at the URI, and if a segment matches a category url title, the variables are set, containing the values of that category. That would include any special characters.

  98. 98 Albert May 7th 2010, 12:27

    Hi Low,
    thanks for your explanation. So, special characters should be ok. I tried again and it stil not worked, so I looked at the tables directly within phpmyadmin, and
    Möbel ist saved at M&# 246;bel (I just split it up, so one can see the the entity. I assume the different encodings are what it makes impossile to use special characters.
    Now I just have to figure out, why categories like “alte moebel” do not work. I assume it´s also an encoding issue.

  99. 99 jaxbulls May 18th 2010, 21:20

    I’m having trouble using this correctly on an MSM site.
    I have 2 sites each with their own templates and 1 set of weblogs. So I publish one weblog and it goes to two different sites with different templates.

    Everything works fine on the default site but all the seg2cat fields in site 2 return null because it seems the categories belong to site 1.

    Is there any way to fix this or add a site parameter like someone above suggested?

  100. 100 Jaxbulls May 18th 2010, 21:31

    I fixed my problem above by removing
    “AND site_id = ‘{$site}’” from lines 88-89 in your extension. That way it doesn’t respect the site of the category I’m trying to view.

  101. 101 Brian May 21st 2010, 17:35

    I made a small change to add {last_segment_category_XX}

    foreach ($query->result as $k => $row)
    {
    // overwrite values in data array
    $data[’segment_’.$ids[$row[’cat_url_title’]].’_category_id’] = $row[’cat_id’];
    $data[’segment_’.$ids[$row[’cat_url_title’]].’_category_name’] = $TYPE->light_xhtml_typography($row[’cat_name’]);
    $data[’segment_’.$ids[$row[’cat_url_title’]].’_category_description’] = $row[’cat_description’];
    $data[’segment_’.$ids[$row[’cat_url_title’]].’_category_image’] = $row[’cat_image’];
    $cats[] = $row[’cat_id’];

    if($ids[$row[’cat_url_title’]] == count($query->result))
    {
    $data[’last_segment_category_id’] = $row[’cat_id’];
    $data[’last_segment_category_name’] = $TYPE->light_xhtml_typography($row[’cat_name’]);
    $data[’last_segment_category_description’] = $row[’cat_description’];
    $data[’last_segment_category_image’] = $row[’cat_image’];
    }
    }

  102. 102 Brian May 21st 2010, 18:01

    Wow, I had that wrong, should be:

    foreach ($query->result as $k => $row)
    {
    // overwrite values in data array
    $data[’segment_’.$ids[$row[’cat_url_title’]].’_category_id’] = $row[’cat_id’];
    $data[’segment_’.$ids[$row[’cat_url_title’]].’_category_name’] = $TYPE->light_xhtml_typography($row[’cat_name’]);
    $data[’segment_’.$ids[$row[’cat_url_title’]].’_category_description’] = $row[’cat_description’];
    $data[’segment_’.$ids[$row[’cat_url_title’]].’_category_image’] = $row[’cat_image’];
    $cats[] = $row[’cat_id’];

    if($ids[$row[’cat_url_title’]] == count($ids))
    {
    $data[’last_segment_category_id’] = $row[’cat_id’];
    $data[’last_segment_category_name’] = $TYPE->light_xhtml_typography($row[’cat_name’]);
    $data[’last_segment_category_description’] = $row[’cat_description’];
    $data[’last_segment_category_image’] = $row[’cat_image’];
    }
    }

  103. 103 ren June 13th 2010, 14:44

    Hi Low,
    Is there a chance to get category name from category_id in url with this extension. I’m trying to figure this out for days.
    Tnxs for advance,
    Ren

  104. 104 Jaxbulls June 17th 2010, 21:24

    @Brian that is awesome.
    I’d love to see it expanded by you or Low so that you could have {second_last_segment_category_id}. I can’t use the {last_segment_category_id} all the time because it fails on pages with Pagination, but if I had the {second_last_segment_category_id} I could get it to work.

  105. 105 Pesche July 22nd 2010, 16:04

    Hey Low

    As of now, {segment_x_category_id} returns the first category id the url title matches to. If you have several categories with the same name / url title across different weblogs, this messes things up. Just wanted to inquire wether you’re aware of this and maybe if you plan to add such feature (e.g., restricting the tags to a specific weblog).

    Regards
    Peter.

  106. 106 Low July 22nd 2010, 16:10

    Hey Peter. I am aware of this, and there has been a caveat in the docs since version 1.0. :)

  107. 107 Pesche July 22nd 2010, 16:21

    Bummer :) What’s the license for the extension, can I go and poke around? Do you by any change have it on GitHub or similar to we can fork it?

  108. 108 Low July 22nd 2010, 16:24

    Don’t worry — I’ll take a look and see if I can add a setting to limit the query by category group.

  109. 109 Adam Chronister July 23rd 2010, 06:55

    I think this has changed. Has is not.

  110. 110 William July 23rd 2010, 17:25

    Hi there !

    I can make the plugin work only for one category

    when I go to example.com/template_group/template/category_1
    I can see my category name, description and image

    but if I go to example.com/template_group/template/category_2 or category_3 I have a blank page :(

    here’s my code :
    {exp:channel:entries channel=”products” category=”{segment_3_category_name}” dynamic=”off” category_group=”1″}
    {segment_3_category_image} <h1>{segment_3_category_name}</h1> {segment_3_category_description}
    {/exp:channel:entries}

    Any ideas why ?

    Thanks
    William

  111. 111 Low July 23rd 2010, 17:28

    Hey William. The category parameter expects an ID. So use {segment_3_category_id} instead of the name.

  112. 112 William July 23rd 2010, 17:42

    Wow ! thanks for the fast reply Low

    it all works fine now :)

  113. 113 William July 26th 2010, 11:57

    Hi again !

    weird i can’t post

  114. 114 William July 26th 2010, 12:00

    ho yes I can !

    there is something I don’t understand. Let me explain :)
    I want to have urls like this for category presentation page example.com/ template_group/ template/ name_of_category
    which is done, thx to seg2cat

  115. 115 William July 26th 2010, 12:01

    and I also want urls like this for the product page of one of the categories example.com/ template_group/ template/ name_of_category/ name_of_entry

    how can I link to the products page from my category page with this url ?
    If I put title_permalink it’s going to send to example.com/ template_group/ template/ name_of_entry

  116. 116 William July 26th 2010, 22:48
  117. 117 akc August 3rd 2010, 07:58

    I just updated to EE2, and so I also updated to seg2cat v2.4.

    I am now getting the following error:

    “Severity: Notice
    Message: Undefined index: News
    Filename: extensions/ext.low_seg2cat.php
    Line Number: 167″

    The same error is cited for line numbers 168 - 172.

    These errors only show up on pages with the URL mydomain.com/news/[…] — and I do have a category named “News”. I’m afraid the solution is obvious and I’m not seeing it… any help is appreciated!

  118. 118 Low August 3rd 2010, 08:38

    akc, can you make sure the category url title is in all lowercase, both in the DB as in the URI?

  119. 119 akc August 3rd 2010, 09:12

    Low, thanks for the speedy response!

    I did a double-take reading your comment because I know I defined the category URL title in lowercase, as “news”, but it prompted me to scan all the rows in the exp_categories table. There I found another category called “News” with the URL title “News” — it was a remnant from the original EE installation which had some pre-defined default categories. I deleted that default category group, and now the errors are gone.

    Thanks a ton. :)

  120. 120 Steve August 10th 2010, 04:21

    Hey Low,
    The extension seems to be running great except for one inconsistency I’m seeing. It *seems* to be affecting {comment_total} when I use {segment_n_category_id} when listing blog summaries. I can send you a link to the site that is currently live. When I disable the extension and hard-code the category id, it’s giving an accurate total.

    Any suggestions are greatly appreciated.

  121. 121 Low August 10th 2010, 09:27

    Steve, I can’t see how Seg2Cat could affect {comment_total}. If it’s outputting the right category id (and I guess you checked that it does), then that’s all there is to it — it doesn’t do anything else…

  122. 122 Steve August 10th 2010, 14:52

    I figured the same thing. I’m not sure if EE2 is having a caching issue or not. The Comments Total isn’t updating when a comment is posted. I’ll keep an eye on it. Thanks

  123. 123 Paul Steven August 10th 2010, 16:33

    Where are the docs for this extension? There appears to be notning on http://loweblog.com/software/low-seg2cat/docs/

  124. 124 Low August 10th 2010, 17:33

    Paul, there is something there. Between that and the overview, that’s all you need to know, as far as Seg2Cat is concerned.

  125. 125 Lincoln August 20th 2010, 17:48

    Hi Low,
    Just to say thanks!

Leave a comment



Some html (a, em, strong, etc) allowed.
Email won’t be displayed and takes care of your Gravatar.