ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Help with categories, please...

July 20, 2012 4:45pm

Subscribe [3]
  • #1 / Jul 20, 2012 4:45pm

    sparky

    17 posts

    After lots of searching, and money spent on plugins, I’m turing here for some help!
    Categories has been the one thing eluding me in Expression Engine, there just doesn’t seem to be a clear, easy way to use them.

    But, I already have a site setup using them and don’t want to go through the hassle of trying to change it now.

    Currently I have a customers site setup like so>

    Resource (if segment_2 is empty) will display the parent categories of all the listings with a count of total posts within the respective categories.

    When you click on one of the parent categories it populates segment_2 and will show the listings. Now I want it to show the sub-categories of the current parent category being displayed.

    Right now I have this setup: Crumbly (to show breadcrumb nav), Child Categories (to display the child categories of the parent being viewed), and Low’s Seg2Cat (to resolve the url segment to the category ID for the Child Categories plugin).

    This works, somewhat… The problem is how the categories are linked.
    Currently it works something like this:

    When viewing the parent category everything shows up like it should (not formated yet just trying to get the code done first).
    The breadcrumbs are there, and you can see the child categories of the parent category being viewed.

    When you click the link for one of the child categories it replaces the parent category segment though!? This then breaks the Child Categories plugin, because the segment it was using to find the child categories is gone.

    So the links looks something like this:

    http://website.com/resources
    >Multiple parent resources here, click on one and you get>
    http://website.com/resources/category/parent
    >Click on one of the child resources and you get>
    http://website.com/resources/category/child  – instead of http://website.com/resources/category/parent/child

    Hope someone can help. I would really like the child categories to link ‘logically’ after the parent, and not replace it.

  • #2 / Jul 20, 2012 9:12pm

    Enviromed

    375 posts

    Have you considered http://devot-ee.com/add-ons/gwcode-categories - free!

  • #3 / Jul 21, 2012 1:44pm

    sparky

    17 posts

    Have you considered http://devot-ee.com/add-ons/gwcode-categories - free!

    I actually tried this plug in as well. Wasn’t accomplishing what I needed. What I really need is to figure out how to get child categories to show up in the url following the parent category like explained above…

  • #4 / Jul 23, 2012 11:45am

    Boyink!

    5011 posts

    I think what you’re fighting at the core is that EE just isn’t designed or coded to display category hierarchy in the URL.  From a URL perspective they are flat.

    I’m not sure if you using the add-ons you mention you can get there - I haven’t done it with categories in the same group but did something similar with categories from different groups (and using Seg2Cat):

    http://www.train-ee.com/courseware/free-tutorials/comments/simple-multifaceted-navigation-using-categories/

  • #5 / Jul 23, 2012 12:48pm

    Dan Decker

    7338 posts

    Hi sparky,

    Thanks for posting your question!

    As Mike notes, ExpressionEngine isn’t quite built to handle categories in the URL like you are after. What you want can be built, but it would be completely engineered in the templates with a nest of conditionals.

    It would save your sanity to focus on the display in the page, your breadcrumbs, rather than the URL. With the add-ons you are using, you have all the info you need to build a reliable breadcrumb, plus Mike’s excellent tutorial!

    So the question becomes, what is your goal? Is it reliable and meaningful breadcrumbs or URLs?

    Cheers,

  • #6 / Jul 23, 2012 1:20pm

    sparky

    17 posts

    Hi sparky,

    Thanks for posting your question!

    As Mike notes, ExpressionEngine isn’t quite built to handle categories in the URL like you are after. What you want can be built, but it would be completely engineered in the templates with a nest of conditionals.

    It would save your sanity to focus on the display in the page, your breadcrumbs, rather than the URL. With the add-ons you are using, you have all the info you need to build a reliable breadcrumb, plus Mike’s excellent tutorial!

    So the question becomes, what is your goal? Is it reliable and meaningful breadcrumbs or URLs?

    Cheers,

    Thanks to both of you for the input! The end goal is definitely reliable and meaningful breadcrumbs. So I will work on the breadcrumbs as apposed to the url and see what I can accomplish that way.

  • #7 / Jul 23, 2012 1:53pm

    sparky

    17 posts

    Ok, so I can easily get some basic breadcrumbs going like so:

    You Are Here:
    {if segment_1 != "" && segment_2 == ""}
    <a href="http://{site_url}">Home</a> → Resources
    {/if}
    {if segment_1 != "" && segment_2 != ""}
    <a href="http://{site_url}">Home</a> → <a href="http://{site_url}{segment_1}">Resources</a> → {segment_3_category_name}
    {/if}
    

    Now, how would I go about determining whether or not segment_3 is a child or parent? And if it’s a parent how do I grab the parent title and link?

    EDIT: segment_2 is the reserved name (category) so that’s why it skips from segment_1 to segment_3 in the breadcrumb structure above.

  • #8 / Jul 23, 2012 2:41pm

    sparky

    17 posts

    OK, I’m close! Just need a little extra help here 😊

    So I got this code to work, and accomplish what I need. The problem is I’m getting php notices on the site now, so something obviously isn’t quite right. Hoping someone with better knowledge of EE/PHP can pinpoint what I’m missing.

    You Are Here:
    {if segment_1 != "" && segment_2 == ""}
    <a href="http://{site_url}">Home</a> → Resources
    {/if}
    {if segment_1 != "" && segment_2 != ""}
    <a href="http://{site_url}">Home</a> → <a href="http://{site_url}{segment_1}">Resources</a> → 
     {if "{last_segment_category_parent_id}" != "0"}
     {exp:child_categories parent="{last_segment_category_parent_id}" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="yes" entries_sort_by="date" entries_sort_direction="asc" entries_limit="1"}
     {parent_category_start}
     <a href="http://{site_url}resources/category/{parent_category_url_title}">{parent_category_name}</a> → {segment_3_category_name}
     {parent_category_end}
     {/exp:child_categories}
     {if:else}
     {segment_3_category_name}
     {/if}
    {/if}
    

    So the part that is throwing error is this:

    {if "{last_segment_category_parent_id}" != "0"}
     {exp:child_categories parent="{last_segment_category_parent_id}" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="yes" entries_sort_by="date" entries_sort_direction="asc" entries_limit="1"}
     {parent_category_start}
     <a href="http://{site_url}resources/category/{parent_category_url_title}">{parent_category_name}</a> → {segment_3_category_name}
     {parent_category_end}
     {/exp:child_categories}
     {if:else}
     {segment_3_category_name}
    {/if}

    If I omit this part, no more errors and everything works great. Add in the code and now the breadcrumbs will work as intended, but php notices pop up. This code simply looks at the last segment and grabs the parent category id. If there is no parent it returns a 0. So I’m saying if the {last_segment_category_parent_id} is not equal to zero then display the parent category name and url.

    Hope this makes sense. Like I said, the code works as intended, just need to squash the bugs now 😉

  • #9 / Jul 24, 2012 11:38am

    Dan Decker

    7338 posts

    Hi sparky,

    What version of ExpressionEngine are you using?

    The PHP errors can appear when parsing conditionals due to the way your variables are used.

    {if {last_segment_category_parent_id} != 0}
     {exp:child_categories parent="{last_segment_category_parent_id}" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="yes" entries_sort_by="date" entries_sort_direction="asc" entries_limit="1"}
     {parent_category_start}
     <a href="http://{site_url}resources/category/{parent_category_url_title}">{parent_category_name}</a> → {segment_3_category_name}
     {parent_category_end}
     {/exp:child_categories}
     {if:else}
     {segment_3_category_name}

    or

    {if last_segment_category_parent_id != 0}
     {exp:child_categories parent="{last_segment_category_parent_id}" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="yes" entries_sort_by="date" entries_sort_direction="asc" entries_limit="1"}
     {parent_category_start}
     <a href="http://{site_url}resources/category/{parent_category_url_title}">{parent_category_name}</a> → {segment_3_category_name}
     {parent_category_end}
     {/exp:child_categories}
     {if:else}
     {segment_3_category_name}

    May get around the errors.

    Cheers,

  • #10 / Jul 24, 2012 12:36pm

    sparky

    17 posts

    Using EE2, will try the above examples and let you know if it works 😉

    EDIT: neither case works. Still getting the same php error notices.

  • #11 / Jul 25, 2012 11:26am

    Dan Decker

    7338 posts

    Hi Sparky,

    Maybe I can poke it close up? Be on the lookout for an email from EllisLab.

    Cheers,

  • #12 / Jul 25, 2012 1:54pm

    sparky

    17 posts

    Sunds good Dan,

    I have another post going over at Devot-ee with the Child Categories developer hoping to get some direct support there as well.

  • #13 / Jul 26, 2012 1:37pm

    Dan Decker

    7338 posts

    Hi sparky,

    Be sure to reply to the email request so we can get crackin’! If you haven’t gotten one, look in your junk mail filter or let me know to send it again.

    Thanks!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases