0

My company website is setup as such:

Product Categories
    -Chairs
        -Armchairs
        -Dining Chairs
    -Tables
        -Dining Tables
        -Coffee Tables

I am trying to adjust how I filter the products on a page. So far, I am only able to filter them based on the product fields, using the code below. (*Note - here I am filtering products by the manufacturer product field.)

{embed="linea/display-products" paginate_base="{segment_1}/page" search="search:manufacturer='Viccarbe'" limit="12" order-by="title"}

However, I need to be able to filter products based on the product categories rather. I am using the Low Seg2Cat addon, and have tried using the code below, as suggested in an alternate post.

{embed="linea/display-products" paginate_base="{segment_1}/page" search="search:manufacturer='Viccarbe' search:{segment_3_category_name}='coffee-tables'" limit="10" order-by="title"}

This also did not work. Any help is much appreciated!

Resources: How do I display a category name based on a segment?

*Edit - This is the embedded channel entries tag - {exp:channel:entries channel="product" {embed:search} category="{segment_3_category_id}" limit="{embed:limit}" paginate="bottom" paginate_base="{embed:paginate_base}" orderby="{embed:order-by}|title" sort="asc|asc"}

  • You'll probably get a better answer if you include your embed template please, as we need to see where the search parameter is actually applied (to the channel:entries tag). – Blatant Jul 3 '15 at 11:59
  • Would you need the entire template, or just the "channel:entries" line of code? Adding line of code to post now. Thank you @Blatant – GNDesign Jul 3 '15 at 17:44
0

I'll take a stab, first your embed, don't pass the category stuff in the search string, so :

{embed="linea/display-products" 
  paginate_base="{segment_1}/page"
  search="search:manufacturer='Viccarbe'" 
  limit="10" 
  order-by="title"
}

Ok, we don't need to pass the segment category ID / Name into the embedded template, its available there too, so first I'll simplfy the channel tag to reflect a working (but without category) mode :

{exp:channel:entries 
  channel="product"
  limit="{embed:limit}" 
  paginate="bottom" 
  paginate_base="{embed:paginate_base}" 
  orderby="{embed:order-by}|title" 
  sort="asc|asc"
  {embed:search}
}
  {!-- ... --}
{/exp:channel:entries}

Ok, so now hopefully GNDesign can confirm this works without category filtering, obvisouly if not please post back withwwhat you did to correct this. Now we refer to the documents as you have https://ellislab.com/expressionengine/user-guide/add-ons/channel/channel_entries.html#category

So, we need the Category ID for the categoy parameter of the channel:entriees tag. Again OP can you confirm that {segment_3_category_id} is putting the correct number out?? (Print it out in the embed, outside the channel entries loop to confirm).

ok, so we could add it back into the paramters like you implied by your edit code. Wait a cotton picken minute! What if the channel:entries tag is parsed before the seg2cat tag?? Parse Order strikes again! Ok, so we review our embed tag, we'll parse this is as a seperate embed parameter, embeds are passed very late o this should be populated by now :

{embed="linea/display-products" 
  paginate_base="{segment_1}/page"
  search="search:manufacturer='Viccarbe'" 
  limit="10" 
  order-by="title" 
  category-id="{segment_3_category_id}"
}

So, this should guarantee that the {segment_3_category_id} is parsed before the embed, and it's passed in as a seperate parameter. Now we just need to plug it into the embed...

{exp:channel:entries 
  channel="product"
  limit="{embed:limit}" 
  paginate="bottom" 
  paginate_base="{embed:paginate_base}" 
  orderby="{embed:order-by}|title" 
  sort="asc|asc"
  category="{embed:category-id}"
  {embed:search}
}
  {!-- ... --}
{/exp:channel:entries}

That should do it. Let us know how you fare! Of course if you still have issues I'd recommend dropping the limit, paginate, paginate_base, order_by and sort parameters from your channel entries tag and paginate_base, limit and order-by from your embed tag, this cleans up the stuff so its easier to debug, you can add it back later.

Please let us know how you fare!

| improve this answer | |
  • I cannot thank you enough for the time and effort you put into this. So I am able to print out the correct category_id. But products are no longer categorized by product category. I should add, the site already displays products based on category. But I am trying to figure out to create a new page, for example - a sale with only dining chairs. (Although I haven't implemented it successfully) everything you are saying makes sense. My one question would be how the embed tag is supposed to determine what specific category I want to show when it is set up dynamically. – GNDesign Jul 3 '15 at 19:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.