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.

Brainstorming the best way to setup the Channels for a products section. $

July 21, 2012 12:47pm

Subscribe [4]
  • #1 / Jul 21, 2012 12:47pm

    5BYFIVE Creative

    159 posts

    $50 to whoever provides the best method first 😊

    I have 3 different product pages ProductsAA, ProductsBB, and ProductsCC. Each page will have a different product line

    On a product page there are multiple product categories with multiple products under each category. For example, on the ProductsAA page there might be Food and Animals. There would be multiple categories listed under those, such as Fruits, Veggies, and Meats.

    -Food
    —-Fruits
    —-Veggies
    —-Meat
    -Animals
    —-Cats
    —-Dogs
    —-Birds

    The side nav on a products page will resemble the diagram above. When clicking on Fruits in the navigation, the fruit entries will be displayed in the main content area, such as apple and orange. The wireframe image I attached should help explain the setup.

    -Food
    —-Fruits
    ———apple
    ———orange
    —-Veggies
    ———broccoli
    ———cauliflower
    —-Meat
    ———chicken
    ———beef
    -Animals
    —-Cats
    ———siamese
    ———calico
    —-Dogs
    ———bulldog
    ———pitbull
    —-Birds
    ———eagle
    ———parakeet

    I can see a few ways to do this, but none really stand out as the “best” way for me or for my client to make updates easily.

    If the main categories(Food, Animals) didn’t need to change, I could hard code those into the template, then make the sub categories(Fruits, Veggies, Meat) entries that include a playa field. I could relate the products (which would be entries in a different channel) (apple, orange, etc.) to those entries. BUT there is the possibility that the main categories(Food, Animals) could be added to or updated in the future.

    There might also be a way to do this using categories in EE, but I don’t have much experience with categories and category url’s.

    What is the best way to set this up so it’s easy for the client and allows all sections to be updated in the future. Thanks for any help!

  • #2 / Jul 22, 2012 8:59am

    John St-Amand

    865 posts

    I think based on your description, categories may work just fine and be quite manageable for your client. The good news is, categories and category urls aren’t too tough to work with - EE does some of the work for you with the parsing engine detecting the category view and behaving accordingly.  They’re not always ideal to work with, but the functionality you’re looking for on the front end is very much in keeping with how EE categories work.

    The simple setup would be a single “index” category with the entries loop occupying the right column and a categories loop on the left.  You leave dynamic set to “yes” in the categories loop, and then when the category is selected, the loop limits itself to the active category from the url.

    The caveats would be as follows:

    1) Most important - category URLs are required to be unique - because they inform EE what entries to display.  SO think of them as url titles for your entries.  You can’t have two with the exact same URL title - even if they don’t share the same parent category up the line.  Within a category group, one URL title for each category.

    2) next/back linking WITHIN a given category is not easily done without the help of some add-ons. Not sure if you would need it, but I thought I’d mention it.

    3) Category URL title nesting (i.e. /products/food/fruit/apple/etc.) is not possible natively, I don’t believe.  I’ve had to use a couple of different add-ons to achieve this kind of semantic category url structure before, so it is possible, but it takes a little bit of extra planning when setting up the templates. Natively you’ll tend to see products/category/category_name

    Hope that helps.

  • #3 / Jul 24, 2012 10:01pm

    5BYFIVE Creative

    159 posts

    John,

    Thanks for your help! I’m jumping around projects right now, but I’m definitely going to look into what you’ve posted. The URLs would probably be something like ProductAA/Food/Fruits. ProductAA would the template group and it shouldn’t go 4 deep. Does this seem doable?

  • #4 / Jul 25, 2012 7:02am

    John St-Amand

    865 posts

    Generally yes, though you will definitely need a couple of add-ons to make it happen.  Once you set it up correctly, the segments in the URL will be unlimited, effectively.

    I used Mo Variables to be able to target the last segment when pagination is not in effect and the second last segment when pagination is in effect. Mo variables add reverse segment global variables, so it’s terrific for this.  Basically the idea is to use those global variables to grab the segment that hold the category url title that matters to the entries.  That gets you halfway there.

    So when the URL structure is productsAA/parent_category/child_category/grandchild_category

    You want to be able to dynamically tell the entries loop that you want only the entries assigned to the grandchild category (i.e. the last segment).  If there were enough of them on that view to be paginated, you have a problem - the category url title segment isn’t then the last segment but the second last segment. That’s where I found Mo Variables was the solution, giving you the ability to “detect” the pagination segment using its pagination detect conditional.  Then you can instead select the second last segment:

    So when the URL structure is productsAA/parent_category/child_category/grandchild_category/P10

    Trouble is, once you grab the url title for the category you want to display, it actually can’t be used in the entries loop.  There’s no parameter for category url title.  You need to convert it to a category ID to be able to make use of it.  LowSeg2Cat is what I used in my case for this.  You feed it a segment url title, and it will look through your categories and give you back info about that category when it finds it.  As always, the category url titles must be unique in EE for this to work, since it will only give you back the first one it finds.  In doing this, you can then get back the category ID to use in the entries loop.  You may have to do a little bit of parse order trickery to pull it all together, but it’s really just those two things.  If the URL structure will always contain the category_url_title of the category you’re intending to view, that becomes your pattern for displaying your entries.  Just set dynamic=“no” and instead feed the entries loop with data about that segment using Seg2Cat.

    And you would do all of this with a single index in your productAA template group.

    Hope that helps!

  • #5 / Jul 27, 2012 4:49pm

    5BYFIVE Creative

    159 posts

    John,

    I think I might have got this worked out using the GWcode and LowSeg2Cat plugins on a test install of EE. I wish the documents for the plugins weren’t so tailored to devs. There are designers who use EE as well and sometimes it’s tough to figure out what a plugin actually does. But, I installed them and played with all options until I figured them out. Thanks a lot for your help! Check for a PM from me.

    I’ll also post the template code I used once I make sure I’m good. Seems like it could hel pa lot of people.

  • #6 / Oct 11, 2012 6:55am

    Damien Buckley

    62 posts

    John,  I’m tackling the same problem.

    How did you get the second last segment category id?  I cant find any way to get the second last category id in mo variables, seg2cat or URL Helper. I can get the second last segment url but not he category id’s : (

  • #7 / Oct 13, 2012 8:08am

    John St-Amand

    865 posts

    In my case, i was only targeting that last segment, basically ignoring all previous segments.  Because of the way categories work in EE (they’re not canonical) all the other segments, through which you virtually display a canonical relationship between category URL titles, are just there for display purposes.  If you have the option in the category preferences of “auto assign entries to category parents” (I can’t remember exactly what language is used for this in the CP, but it’s something like this) the canonical relationship can exist - at least virtually.

    So for example, if you have a products category group with a top-level category of sunglasses and a child category of oakley assigned to sunglasses, you would logically look to have a category url structure of:

    domain.com/products/sunglasses

    and

    domain.com/products/sunglasses/oakley

    But despite parent and child relationships being part of the category setup in EE, they don’t actually maintain a canonical structure.  That’s why every category URL within a given category group must be unique.  If you create two categories, even within different parents, within the same category group, when you display your entries on the basis of a category url segment (rather than cat id) you will get BOTH groups, because EE won’t know how to distinguish between them on the basis of parent.

    If you have the auto-assign to parent option enabled, if the product has been assigned to “Oakley” is has also automatically been assigned to “sunglasses”.  That helps a bit.

    So in my case, I proceeded with the strict rule that no two categories would have the same name.  Them my lookups would work.  All I ha to do is narrow the display of the entries on the basis of the ID of the final segment in the URL, dynamically filling the category segment with the id of the last segment (you may need to detect pagination to avoid having Seg2Cat attempt a lookup on the basis of last segment then - you want the last segment that is not a pagination segment).  Mo Variables has a {if paginated} offset that would allow you to determine if paginated and then target either the last segment or the second last segment accordingly.  It also has reverse segments. That combination ought to make it possible to do what i did with a single add-on.

    Hope that helps.

  • #8 / Oct 14, 2012 7:44pm

    Damien Buckley

    62 posts

    Hi John. Thanks for the detailed response. I was more curious how you managed to get the category_id of the second-last segment when pagination kicks in but I see now it wasnt a problem as you didnt have varying depth of categories.

    My problem is that I have in some instances one level of categories and in others two or even three so getting the second-last where pagination was involved was a bit of a nightmare although I did solve it in the end.

    In this snippet Mo Variables provides the conditional for pagination. URL Helper helps me get the parent_segment thus avoiding the pagination suffix. cat2id turns that into a category ID. Seg2cat gets last-segment category id where not paginated:

    {if paginated}{exp:cat2:id category_url_title='{parent_segment}' category_group="1"}{/if}{if not_paginated}{last_segment_category_id}{/if}

    I’m then calling the channel:entries tag from an embed with the snippet passed as an embedded variable to work around parsing order:

    {embed='products/_list' catlist='{snp_category}'}
    {exp:channel:entries
        orderby="title"
        sort="asc"
        channel="products"
        disable="member_data"
        dynamic="no"
        category="{embed:catlist}"
        limit="12"
        paginate="bottom" 
        }

    I’m certain there are more elegant ways of doing it or even that extension developers could work around this in 5 minutes but as a non-programmer, I got it working this way so for now it will have to do.

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

ExpressionEngine News!

#eecms, #events, #releases