I have a products section where I give each product group a main category. Initially I had it setup where each product had a main category and a sub category. GWCode generated a side nav from the catgories that looks like this...
- Shampoos ( /products/shampoos/ )
- Brand1 ( /products/shampoos/brand1/ )
- Brand2 ( /products/shampoos/brand2/ )
- Soaps ( /products/soaps/ )
- Brand3 ( /products/soaps/brand3/ )
- Brand4 ( /products/soaps/brand4/ )
URL setup...
/products/shampoos(category)/ = list of all shampoo products /products/shampoos(category)/brand1(subcategory)/ = list of all shampoo products with the Brand1 category /products/shampoos(category)/brand1(subcategory)/flowers(url_title) = single entry displaying the "flowers" entry
In my template I use Switchee to show a list of products when segment_3 is blank. If segment_3 is not blank I use if statements to detect if segment 4 is blank or not. If it is I show a list of products. If it is not blank I show the single entry product details. This worked GREAT until the client informed me that the products won't always have a subcategory. Which means this url setup is possible as well...
/products/shavinggel(category)/ /products/shavinggel(category)/coolmint(url_title)
So now the switchee and if statements I have setup won't work in this situation. I'm trying to figure out if there is a way to detect if segment_3 is a url_title or a category_url_title and display the appropriate code. Or if you have any other ideas.
Simplified template setup...
{exp:switchee variable = "{segment_3}" parse="inward"}
{case value="''"}
{exp:channel:entries channel="products" category="{segment_category_ids}" disable="member_data|pagination" sort="asc" dynamic="no"}
<!-- display list of entries from main category -->
{/exp:channel:entries}
{/case}
{case value="" default="Yes"}
{if segment_4 == ""}
{exp:channel:entries channel="products" category="{segment_category_ids}" disable="member_data|pagination" sort="asc" dynamic="no"}
<!-- display list of entries from sub category -->
{/exp:channel:entries}
{/if}
{if segment_4 != ""}
{exp:channel:entries channel="products" disable="member_data|pagination" sort="asc" url_title="{segment_4}" dynamic="no"}
<!-- display single entry detail page -->
{/exp:channel:entries}
{/if}
{/case}
{/exp:switchee}