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

Get Category of Parent within the {parents} tag

How Do I?

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

I have two channels - Parent and Child

Parent: Batteries. This Channel has categories. I create an entry in Battery (ex: AAA) and add it to the “Disposable” category. I then relate this entry to it’s brand: Panasonic.

So the end result is it is AAA, Disposable and is Panasonic

Child: Brand This is just a channel where I create all the brands

What I am trying to do: Create a page where I list all batteries and sort them by brand and show the type - disposable or rechargeable (which are categories).

This is what I have so far. Showing the categories is where I’m having trouble and help will be appreciated.

<div class="row">
 <div class="col-sm-12">
  {exp:channel:entries channel="brands" dynamic="no" orderby="title" sort="asc"}
   <div class="row clearfix m-b-50">
    <h2>{title}</h2>
    {parents field="brand" channel="batteries" orderby="title" sort="asc" limit="6"}
        <div class="col-md-2">
         Type: {categories}{category_name}{/categories}

         <a href="/{segment_1}/{parents:url_title}">{parents:title}</a>
        </div>
    {/parents}
   </div>
  {/exp:channel:entries}
 </div>
</div>
       
Derek Jones's avatar
Derek Jones
7,561 posts
8 years ago
Derek Jones's avatar Derek Jones

Very close, conradical. Inside the parents tag pair, the category tag pair itself needs to be namespaced by parents, so:

{parents:categories}{category_name}{/parents:categories}
       
conradical's avatar
conradical
8 posts
8 years ago
conradical's avatar conradical

Ah! Thank you.

       

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.