We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Relationship help.

How Do I?

conradical's avatar
conradical
8 posts
9 years ago
conradical's avatar conradical

For the shorter version, see the attached image below.

I have a puzzler.. at least for me. I’ve spent time drawing it on paper, then writing quick templates and channels but can’t get what I need. Maybe I’m approaching it incorrectly.

I would appreciate help with the relationship field - or even a completely new approach that I did not think of.

This is the content architecture of a site:

Battery Mode (Rechargeable, Disposable) Battery Type (Alkaline, Zinc) Brand (Panasonic, Energizer) Batteries (AA, AAA)

So a full URL would be: /rechargeable-batteries/alkaline/panasonic

I’ve attached an image so it is easier to visualise.

What I have done is create 3 channels: 1. Brands 2. Batteries 3. Products

The Battery Channel has categories like Rechargeable and Disposable. So I can create a battery and add it in either category.

I created brands channel and added a relationship field for batteries. So AA battery (from the battery channel) could be added to multiple brands like Panasonic, Energizer etc.

I figured so far I have abstracted the content. Now I created a Products channel where I create the Battery Type as channel entries (Alkaline) and then with a relationship field select the brands offered in this battery type.

So I was hoping that when I relate the brand in this channel, I can then get all the children (batteries) along with their category (rechargeable,disposable) and display them accordingly.

Ex: If segment 1 is rechargeable-batteries then I would get the batteries from the brand based on segment 1 category ID (Low Seg2Cat).

Maybe I’ve gone about it the wrong way or maybe there is an easy solution. Here is what I have so far - in template code.

Template: Rechargeable Batteries (Same naming convention as battery categories)

{embed="_includes/header"}
{if segment_2 == ""}
 {embed="rechargeable-batteries/landing"}
{/if}
{if segment_2 != ""}
 {embed="rechargeable-batteries/battery"}
{/if}
{if segment_3 != ""}
 {embed="rechargeable-batteries/brand"}
{/if}
{embed="_includes/footer"}

Battery Mode page:

<ul>
 {exp:channel:entries channel="products" category="{segment_1_category_id}" dynamic="no"}
  <li><a href="http://{url_title}">{title}</a></li>
 {/exp:channel:entries}
</ul>

Battery Type:

{exp:channel:entries channel="products" category="{segment_1_category_id}" url_title="{last_segment}" dynamic="no"}
 <h1>{title}</h1>
 {products}
  <a href="/{segment_1}/{segment_2}/{products:url_title}/">{products:title}</a>
 {/products}
{/exp:channel:entries}

Brand Page: This is where the problem is. It is in a state of a mess as it is what I had last, after hacking and tweaking it to death.

{exp:channel:entries channel="batteries" category="{segment_1_category_id}" url_title="{segment_2}" dynamic="no"}
 <h1>{title}</h1>
 {parents}
  {parents:title}
 {/parents}
{/exp:channel:entries}
       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.